NSPredicate 不区分大小写的字符串搜索 CloudKit

NSPredicate case insensitive string search with CloudKit

我正在尝试搜索 CloudKit 对象的字符串字段。以下行成功编译并运行没有错误。

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

然而,当我尝试添加不区分大小写的搜索时,应用程序崩溃了。

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

有错误:

*** 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"})'

来自 CKQuery 的文档: "String-based comparisons are case insensitive but otherwise all comparisons must be an exact match of the specified value."

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

所以我认为 BEGINSWITH 就是您所需要的。你没发现是这样吗?