I’m trying to perform a search on some results from a JSON feed that have been loaded into an NSArray called tableData and then displayed in a UITable.
The searchResults NSArray has been declared the .h file. The problem is that at the moment searchResults are empty and output nothing to the console. I’m not sure why…
I’m wondering if there’s something missing from the
searchResults = [tableData filteredArrayUsingPredicate:resultPredicate];
line of code below
thanks for any help.
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
searchResults = [tableData filteredArrayUsingPredicate:resultPredicate];
NSLog(@"searchResults: %@", searchResults);
NSLog(@"tableData results: %@", tableData);
}
If you are looking for a field called ‘cat’ in your Dictionary, instead of having the predicate look in SELF, it should look in SELF.cat.
If you still need to check other fields contained within the object, you can create a compound predicate. Details on Predicates can be found in Apple’s Predicate Programming Guide.