简体   繁体   English

CloudKit NSPredicate的意外表达

[英]CloudKit Unexpected Expression for NSPredicate

I'm using CloudKit and wish to perform a search for records based on their string fields. 我正在使用CloudKit并希望根据字符串字段搜索记录。

Apple docs say this is the way to do a tokenized search of a record's fields: Apple文档说这是对记录字段进行标记化搜索的方法:

To perform a tokenized search of a record's fields, use the special operator self. 要对记录的字段执行标记化搜索,请使用特殊运算符self。 A tokenized search searches any fields that have full-text search enabled, which is all string-based fields by default. 标记化搜索会搜索启用了全文搜索的任何字段,默认情况下这是所有基于字符串的字段。 Listing 5 shows an example that searches the fields of the record for the token strings bob and smith. 清单5显示了一个示例,它在记录的字段中搜索令牌字符串bob和smith。 Each distinct word is treated as a separate token for the purpose of searching. 为了搜索,每个不同的单词被视为单独的标记。 Comparisons are case- and diacritic-insensitive. 比较是不区分大小写和不区分大小写的。 These token strings may be found in a single field or in multiple fields but all of the tokens must be present in a record for it to be considered a match. 这些令牌字符串可以在单个字段或多个字段中找到,但是所有令牌必须存在于记录中才能被视为匹配。

Listing 5: Matching a field containing a tokenized string 清单5:匹配包含标记化字符串的字段

 NSPredicate predicate = nil; predicate = [NSPredicate predicateWithFormat:@"self contains 'bob smith'"]; 

When I enter this exact string for the predicate, I get the an exception. 当我为谓词输入这个确切的字符串时,我得到一个例外。

Code: 码:

predicate = [NSPredicate predicateWithFormat:@"self contains 'bob smith'"];
query = [[CKQuery alloc] initWithRecordType:kCKRecord_Level predicate:predicate];

Exception: 例外:

*** Terminating app due to uncaught exception 'CKException', reason: 'Unexpected expression: SELF CONTAINS "bob smith"'

Any ideas what could be wrong? 什么想法可能是错的? Has anyone had any success with that predicate string and CloudKit? 有没有人使用该谓词字符串和CloudKit取得任何成功?

https://developer.apple.com/library/prerelease/ios/documentation/CloudKit/Reference/CKQuery_class/index.html https://developer.apple.com/library/prerelease/ios/documentation/CloudKit/Reference/CKQuery_class/index.html

It looks like the 'self contains' does not work anymore. 看起来'自包含'不再起作用了。 You still do a tokenized search using this predicate: 您仍然使用此谓词进行标记化搜索:

NSPredicate(format: "allTokens TOKENMATCHES[cdl] %@", "bob smith")

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

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