In Cocoa, parallel arrays are a path to doom and ruination. You can't use them effectively with Bindings, so you'll have to write a lot of glue code instead, as if Bindings didn't exist. Moreover, you're killing off any future AppleScript/Scripting Bridge support you may intend to have before you even begin to implement it.
The correct way is to create a model class with name
and age
properties, and have a single array of instances of that class. Then, to find an item by name or age, use NSPredicate
to filter the array, and indexOfObjectIdenticalTo:
to find the index of each item from the filtered array in the main array.
The difference between indexOfObject:
and indexOfObjectIdenticalTo:
is that the former will send isEqual:
messages to determine whether each object is the one it's looking for, whereas the latter will only look for the specific object you passed in. Thus, you can use indexOfObject:
with an object that isn't in the array but is equal to one that is, in order to find the equal object in the array.