开发者

Case Insensitive Core Data CONTAINS or BEGINSWITH contraint

开发者 https://www.devze.com 2022-12-15 19:18 出处:网络
I have a predicate that looks like [NSPredicate predicateWithFormat:@\"region=%@ && locality CONTAINS %@\", self.region, query];

I have a predicate that looks like

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

I want it to开发者_C百科 match ignoring case. Whats the trick?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消