Reputation: 5823
I have an array of person_name###country_name:
Bob###USA
Tim###UK
Sandy###German
I have a UISearchBar which looks for person name(ie. does not consider country), the following NSPredicate searches person name as well as country, how do I re-construct it so it only looks for person name?
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[cd] %@", __searchTerm];
NSArray *result = [self.source filteredArrayUsingPredicate:predicate];
the array of person###country is created by some complex way, so do not suggest me create another array with only person names, also, different countries can have different people of the same name.
Thanks a lot!
Upvotes: 0
Views: 443
Reputation: 243146
You would use BEGINSWITH
instead of CONTAINS
.
But really: if the two pieces of data are separate, why are you storing then in the same string? You should break them apart and create a new class with two properties: name
and country
. That will make all of this much simpler.
Upvotes: 1