Searching NSArray of NSDictionary objects

NSArray *contacts = ...; //your array of NSDictionary objects
NSPredicate *filter = [NSPredicate predicateWithFormat:@"contact_type = 42"];

NSArray *filteredContacts = [contacts filteredArrayUsingPredicate:filter];

After this, filteredContacts will contain only the contacts whose contact_type is 42.

If you need to search for more than one kind of contact_type, then simply use an OR in the predicate:

filter = [NSPredicate predicateWithFormat:@"contact_type = 42 OR contact_type = 23"];

Leave a Comment