I have an array of objects. The objects in the array contain a dictionary as one of its properties and i need to search the values of one of those keys for each object within the array. I need to use a like condition(I think its actually contains in objective-c I may be wrong though). Im using the method _search_results = [_people filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"details[@\"firstName\"] contains %@",searchBar.text]]; which i think will return me all the objects that fit that search condition. Here are my questions
1) Is there another method I can use to do this? Or maybe a different class all in general? Maybe a more efficient method to use?
2) Am i going about searching for the value correctly within the dictionary? Since its a property of the object i think im doing it right. Which the syntax to me looks correct dictionaryName[keyName] contains value
Ive only use NSPredicate with properties of objects, i never had to search a dictionary thats in an object like this. So like i said I think im right here.
In response to the first set of answers
_search_results = [_people indexesOfObjectsPassingTest:^BOOL(PeopleObject *person, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *last_name = person.details[kPersonLastNameKey];
if([last_name containsString:searchBar.text]){
return TRUE;
}
else
return FALSE;
}];
indexesOfObjectsPassingTestis all mixed up. You don't create an index set. You don't manipulate an index set. You write a block that takes a single object as an input, and returns TRUE if it should be made a member of the set, and FALSE if not. TheindexesOfObjectsPassingTestmethod does the work of creating the index set, then using your block to test each item in the array and returning an index set with the objects that pass your test.