I have and array of custom objects of Person Class
Person : NSObject{
NSString *firstName;
NSString *lastName;
NSString *age;
}
NSMutableArray
Checkout this answers it is very similar to what you want
https://stackoverflow.com/a/15375756/1190861
The code in your case will be as the following:
NSMutableDictionary *result = [NSMutableDictionary new];
NSArray *distinctNames;
distinctNames = [personsArray valueForKeyPath:@"@distinctUnionOfObjects.firstName"];
for (NSString *name in distinctNames) {
NSPredicate predicate = [NSPredicate predicateWithFormat:@"firstName = %@", name];
NSArray *persons = [personsArray filteredArrayUsingPredicate:predicate];
[result setObject:persons forKey:name];
}
NSLog(@"%@", result);