简体   繁体   English

如何查询CloudKit的recordID IN [CKRecordID]

[英]How to query CloudKit for recordID IN [CKRecordID]

My predicate wants to exclude some records that are already downloaded and available in a [CKRecordID]. 我的谓词想要排除已经下载并在[CKRecordID]中可用的一些记录。 Now I can query 1 CKRecordID[0], but not the [CKRecordID] array. 现在我可以查询1个CKRecordID [0],但不能查询[CKRecordID]数组。 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) 错误:loadImageCompareRecordIDsAndEndDateThatHaveNotEnded错误:无效谓词:无效谓词:数组成员必须符合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

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

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM