Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case Insensitive Core Data CONTAINS or BEGINSWITH contraint

I have a predicate that looks like

[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS %@", self.region, query];

I want it to match ignoring case. Whats the trick?

like image 625
aussiegeek Avatar asked Jan 10 '10 04:01

aussiegeek


2 Answers

As described in the Predicate Programming Guide, string comparisons in an NSPredicate can be made case insensitive by including a [c] (in square brackets) after the comparison operator (e.g. BEGINSWITH[c]). You can make the comparison diacritic insensitive using a [d] modifier or case and diacritic insensitive with a [cd] modifier. In your example, you would use:

[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS[cd] %@", self.region, query] 

for case and diacritic insensitivity.

like image 151
Barry Wark Avatar answered Oct 03 '22 02:10

Barry Wark


Turns out I need to have a predicate in the form of:

[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS[cd] %@", self.region, query]

and now it is case insensitive

like image 32
aussiegeek Avatar answered Oct 03 '22 03:10

aussiegeek