简体   繁体   English

NSPredicate使用CloudKit进行不区分大小写的字符串搜索

[英]NSPredicate case insensitive string search with CloudKit

I'm trying to search a String field of a CloudKit object. 我正在尝试搜索CloudKit对象的String字段。 The following line successfully compiles and runs without error. 以下行成功编译并运行,没有错误。

NSPredicate(format: "Title BEGINSWITH %@", "Apple")

Yet, when I try add case insensitive search, it the app crashes. 然而,当我尝试添加不区分大小写的搜索时,应用程序崩溃了。

NSPredicate(format: "Title BEGINSWITH[cdl] %@", "Apple")

With error: 有错误:

*** Terminating app due to uncaught exception 'CKException', reason: 'Invalid predicate: Title BEGINSWITH[cdl] "Apple" (Error Domain=CKErrorDomain Code=12 "Invalid operator in <Title BEGINSWITH[cdl] "Apple">: Unsupported operator: BEGINSWITH" UserInfo=0x7fb69d02e910 {ck_isComparisonError=true, NSLocalizedDescription=Invalid operator in <Title BEGINSWITH[cdl] "Apple">: Unsupported operator: BEGINSWITH, NSUnderlyingError=0x7fb69d02e9e0 "Unsupported operator: BEGINSWITH"})'

As from the documentation on CKQuery: "String-based comparisons are case insensitive but otherwise all comparisons must be an exact match of the specified value." 从CKQuery的文档中可以看出:“基于字符串的比较不区分大小写,但所有比较都必须与指定值完全匹配。”

https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKQuery_class/index.html#//apple_ref/occ/cl/CKQuery https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKQuery_class/index.html#//apple_ref/occ/cl/CKQuery

So I think BEGINSWITH is all you should need. 所以我认为BEGINSWITH就是你所需要的。 Have you not found this to be the case? 你有没有发现这种情况?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM