CloudKit - NSPredicate 用于在引用列表中查找包含多个 CKReference 的所有记录
Posted
技术标签:
【中文标题】CloudKit - NSPredicate 用于在引用列表中查找包含多个 CKReference 的所有记录【英文标题】:CloudKit - NSPredicate for finding all records that contains multiple CKReferences in a reference list 【发布时间】:2015-06-15 15:02:37 【问题描述】:我正在开发使用 CloudKit 的 Joke 应用
每个笑话都有一些类别/标签的参考列表。
我正在尝试查询所有带有特定标签的笑话。例如,我想查找属于 Animal 和 Doctor 类别的所有笑话。
现在我已经尝试使用以下代码
let tagRecords = tags.map CKReference(record: $0.record, action: .None)
let predicate = NSPredicate(format: "tags CONTAINS %@", tagRecords)
let query = CKQuery(recordType: "Jokes", predicate: predicate)
基本上上面所做的是首先创建一个引用数组,然后创建一个谓词来查找包含这些引用的标签
不幸的是,这不起作用 我收到以下错误
服务器消息 = "内部服务器错误""
所以问题是:如何在参考列表中找到包含所有参考的所有记录?
【问题讨论】:
【参考方案1】:假设tags
是一个关系或字符串数组,您可以尝试使用以下谓词:
let predicate = NSPredicate(format: "ANY tags IN %@", tagRecords)
希望这会有所帮助。
【讨论】:
我最终得到了以下 let predicate = NSPredicate(format: "ALL %@ in tags", tagRecords)以上是关于CloudKit - NSPredicate 用于在引用列表中查找包含多个 CKReference 的所有记录的主要内容,如果未能解决你的问题,请参考以下文章