5

I'm using following NSPredicate for filtering,

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

It works fine, but it's case-sensitive. I need the filtering should be case insensitive.

I've tried,

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

But it throws the 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 can't understand what it was mentioned in this answer. Can anyone suggest what should I change here in the above filtering?

Community
  • 1
  • 1
Nazik
  • 8,696
  • 27
  • 77
  • 123

1 Answers1

17

Replace all CONTAINS with CONTAINS[c]. The "c" in square brackets means case insensitive. You can also use a "d" to make it diacritic insensitive. This is explained in the "Predicate Programming Guide".

Nazik
  • 8,696
  • 27
  • 77
  • 123
rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • 1
    It's working thanks. I'll google all my coding issues instead of seeing apple documentation. [This answer](http://stackoverflow.com/a/1669433/756941) led me to use `ANY` keyword for case insensitive. Please add the link where it is mentioned in Predicate Programming guide.. – Nazik Nov 10 '14 at 07:42