如何在 CloudKit 中查询 [CKRecordID] 中的 recordID

How to query CloudKit for recordID IN [CKRecordID]

我的谓词想要排除一些已经下载并在 [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

使用 [CKReference] 而不是 [CKRecordID] 解决了这个问题。

明确一点(因为我花了好几个小时才弄对)...

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