Reputation: 8118
I'm having the following core data entities:
Now I have NSArray with all POI entities.
I want to filter that array with a predicate so that it searches on every attribute it has to see if it contains something that the user searches.
For example: Array object 0 : address = Test details = Test1 ..
Array object 1: Address = Ba details = Ba1 ..
and the users searches for the 'e', I want to get an nsarray with only object 0.
I tried like this:
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
searchResults = [_dataArray filteredArrayUsingPredicate:resultPredicate];
But this returns always nothing.
Can someone help me out on this?
Upvotes: 2
Views: 136
Reputation: 1201
Try this
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] \'%@\'",
searchText];
searchResults = [_dataArray filteredArrayUsingPredicate:resultPredicate];
Upvotes: 0
Reputation: 1257
Please try like this;
[NSPredicate predicateWithFormat:@"SELF.propertyName contains[cd] %@", searchText];
Upvotes: 3
Reputation: 5182
Since the _dataArray
contains POI
entities and searching on address
attribute, change the predicate to
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"address contains[cd] %@",
searchText];
searchResults = [_dataArray filteredArrayUsingPredicate:resultPredicate];
Upvotes: 0