How to query CloudKit for recordID IN [CKRecordID]

扶醉桌前 提交于 2019-12-20 12:38:45

问题


My predicate wants to exclude some records that are already downloaded and available in a [CKRecordID]. Now I can query 1 CKRecordID[0], but not the [CKRecordID] array. How can I query the array?

let excludeIDs: [CKRecordID]

This works:

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

But this doesn't:

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

ERROR: loadImageCompareRecordIDsAndEndDateThatHaveNotEnded Error: Invalid predicate: Invalid predicate: Array members must conform to CKRecordValue: ( "", "", "", "", "" ) (CKRecordID)

The other general parts of the code:

    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

回答1:


Using [CKReference] and not [CKRecordID] solved it.




回答2:


To be explicit (because it took me hours to get this right)...

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


来源:https://stackoverflow.com/questions/32900235/how-to-query-cloudkit-for-recordid-in-ckrecordid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!