NSPredicate - Case-Insensitive Filtering for Multiple Conditions

I use the following NSPredicate to filter,

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName CONTAINS %@ ) OR (lastName CONTAINS %@ )OR (UserName CONTAINS %@ ) ", myText,myText,myText]; NSArray *filtered = [responseArray filteredArrayUsingPredicate:predicate]; 

It works great, but is case sensitive. I need the filtering to be case insensitive.

I tried,

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY firstName CONTAINS %@ ) OR (ANY lastName CONTAINS %@ )OR (ANY UserName CONTAINS %@ ) ", myText,myText,myText]; 

But he gives an error

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet.' 

I do not understand what was mentioned in this answer . Can anyone suggest that I should change here in the above filtering?

+5
source share
1 answer

Replace all CONTAINS with CONTAINS[c] . ā€œCā€ in square brackets means case insensitive. You can also use "d" to make it diacritical insensitive. This is explained in the Predicate Programming Guide.

+15
source

Source: https://habr.com/ru/post/1206538/


All Articles