CloudKit NSPredicate 的意外表达式

CloudKit Unexpected Expression for NSPredicate

我正在使用 CloudKit 并希望根据记录的字符串字段执行记录搜索。

Apple 文档说这是对记录字段进行标记化搜索的方法:

To perform a tokenized search of a record’s fields, use the special operator 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. 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

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

当我为谓词输入这个确切的字符串时,出现异常。

代码:

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

异常:

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

有什么想法是错误的吗?有没有人成功使用该谓词字符串和 CloudKit?

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

看来 'self contains' 不再起作用了。您仍然使用此谓词进行标记化搜索:

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