objective-c 不区分大小写的核心数据 CONTAINS 或 BEGINSWITH 约束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2036094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Case Insensitive Core Data CONTAINS or BEGINSWITH contraint
提问by aussiegeek
I have a predicate that looks like
我有一个看起来像的谓词
[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS %@", self.region, query];
[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS %@", self.region, query];
I want it to match ignoring case. Whats the trick?
我希望它匹配忽略大小写。有什么诀窍?
采纳答案by aussiegeek
Turns out I need to have a predicate in the form of:
原来我需要有一个形式为的谓词:
[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS[cd] %@", self.region, query]
[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS[cd] %@", self.region, query]
and now it is case insensitive
现在不区分大小写
回答by Barry Wark
As described in the Predicate Programming Guide, string comparisons in an NSPredicatecan 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:
如Predicate Programming Guide 中所述,NSPredicate通过[c]在比较运算符(例如BEGINSWITH[c])之后包含 a (在方括号中),可以使an 中的字符串比较不区分大小写。您可以使用[d]修饰符使比较变音符号不敏感,或者使用修饰符使变音符号不敏感[cd]。在您的示例中,您将使用:
[NSPredicate predicateWithFormat:@"region=%@ && locality CONTAINS[cd] %@", self.region, query]
for case and diacritic insensitivity.
对于大小写和变音符号不敏感。

