The question was difficult to put into words, but here is my situation. I have several Monster objects in an array called monsters
. Each monster has a name
You could do something like:
let monsters: [Monster] = ...
let monsterNames: [String] = ...
let filteredMonsters = monsters.filter { monsterNames.contains($0.name) }
This doesn't perform all that well, since it will go over the names
array up to n
times for each monster, but if your names
arrays is small, this won't be a problem.