CloudKit NSPredicate的意外表达 [英] CloudKit Unexpected Expression for NSPredicate
问题描述
我正在使用CloudKit并希望根据字符串字段搜索记录。
I'm using CloudKit and wish to perform a search for records based on their string fields.
Apple文档说这是对记录字段进行标记化搜索的方法:
Apple docs say this is the way to do a tokenized search of a record's fields:
要对记录的字段执行标记化搜索,请使用特殊运算符self。标记化搜索会搜索启用了全文搜索的任何字段,默认情况下这是所有基于字符串的字段。清单5显示了一个示例,它在记录的字段中搜索令牌字符串bob和smith。为了搜索,每个不同的单词被视为单独的标记。比较是不区分大小写和不区分大小写的。这些令牌字符串可以在单个字段或多个字段中找到,但所有令牌必须存在于记录中才能被视为匹配。
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.
清单5 :匹配包含标记化字符串的字段
Listing 5: Matching a field containing a tokenized string
NSPredicate predicate = nil;
predicate = [NSPredicate predicateWithFormat:@"self contains 'bob smith'"];
当我为谓词输入这个确切的字符串时,我得到了例外。
When I enter this exact string for the predicate, I get the an exception.
代码:
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取得任何成功?
Any ideas what could be wrong? Has anyone had any success with that predicate string and CloudKit?
推荐答案
看起来自包含不再起作用了。您仍然使用此谓词进行标记化搜索:
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")
这篇关于CloudKit NSPredicate的意外表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!