Reputation: 2562
I have an App with CoreData and I need to use NSPredicate to retrieve all the contacts from a city.
The question is that "city" maybe written like LONDON or London or even london. And the user will type London to search, or LoNDon.
What I need is to use NSPredicate with localizedCaseInsensitiveCompare, so that all the records are retrieved.
Code:
request.predicate = [NSPredicate predicateWithFormat:
@"activityDeleted == %@ && (SUBQUERY(hasMembers, $sub, $sub.memberDeleted == %@).@count > 0) && (SUBQUERY(hasMembers, $sub, $sub.city == %@)",
[NSNumber numberWithBool:NO],
[NSNumber numberWithBool:NO],
city];
The above NSPredicate retrieves all the groups that have Contacts, not deleted, that are in a certain City, but I have the CaseInsensitive problem...
How can I do that?
Thanks,
RL
Upvotes: 0
Views: 476
Reputation: 243146
You don't need subquery here. Your entire predicate can instead be:
@"activityDeleted == NO AND ANY hasMembers.memberDeleted = NO AND ANY hasMembers.city =[cd] %@", city
Upvotes: 1
Reputation: 3847
You can use the case insensitive and diacritic insensitive modifiers "[cd]" on the ==
SUBQUERY(hasMembers, $sub, $sub.city ==[cd] %@)
You might try searching stackoverflow for "case insensitive nspredicate" there are several answers already https://stackoverflow.com/search?q=case+insensitive+nspredicate
Upvotes: 1