如何查询CloudKit的recordID IN [CKRecordID]

时间:2015-10-02 03:41:39

标签: ios nspredicate cloudkit ckquery ckrecord

我的谓词想要排除一些已经下载并在[CKRecordID]中可用的记录。现在我可以查询1个CKRecordID [0],但不能查询[CKRecordID]数组。我该如何查询数组?

let excludeIDs: [CKRecordID]

这有效:

let pred1 = NSPredicate(format: "NOT(recordID = %@)", excludeIDs[0])

但这不是:

let pred1 = NSPredicate(format: "NOT(recordID IN %@)", excludeIDs)

错误: loadImageCompareRecordIDsAndEndDateThatHaveNotEnded错误:无效谓词:无效谓词:数组成员必须符合CKRecordValue :(     “”     “”     “”     “”     “” )(CKRecordID)

代码的其他一般部分:

    let sort = NSSortDescriptor(key: "creationDate", ascending: false)
    let query = CKQuery(recordType: MyRecordTypes.ImageCompare, predicate: pred1)
    query.sortDescriptors = [sort]
    let operation = CKQueryOperation(query: query)
    operation.desiredKeys = ["endDate"]
    operation.resultsLimit = 50

2 个答案:

答案 0 :(得分:8)

使用[CKReference]而非[CKRecordID]解决了它。

答案 1 :(得分:0)

明确一点(因为花了我几个小时才能解决这个问题)

let refs = excludeIDs.map { CKRecord.Reference(recordID: $0.recordID, action: .none) }
let pred1 = NSPredicate(format: "NOT(recordID IN %@)", refs)