In my app I have a class Person with personId property.
Now I need some data structure to hold a bunch of unique Person objects (u
You shouldn't need to worry about this when you're adding items to an array. As long as you're adding a unique object each time, the properties of the object shouldn't matter.
If you're worried about this and want to be doubly sure, use NSMutableSet instead (unless you need to maintain order of each object).
Update
You could use a predicate to check that an object with the same value does not exist before adding it. This would work fine with both NSMutableArray and NSMutableSet.
//create array
NSMutableArray *array = [[NSMutableArray alloc] init];
//create person
Person *newPerson = [[Person alloc] init];
//add person
[array addObject:newPerson]
//check new object exists
if([[array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"personID == %@", [newPerson personID]]] count] == 0)
{
//add object
[array addObject:newPerson];
}
Very rough pseudocode but hopefully you get the gist :)