本文介绍了CloudKit 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:
清单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的意外表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!