I have several custom objects in an NSArray, I need to search through all the objects and fnd the index of the object that has a property which matches a string.
Should I be using a for each loop? I need it to be relatively fast to search each time a new character is entered in a textfield.
I have several custom objects in an NSArray, I need to search through all
Share
NSPredicateis neat, but overkill (and it won’t give you the index of the found object; just the object itself).The paired array approach, which will work, feels odd to me (probably because it’s using a paired array).
I would either use a
for()loop (andbreak;when I found what I was looking for), or use a block enumerator:Or a slightly different variant: