很抱歉有一个愚蠢的简单问题。我想列出创建的所有超过 24 小时的记录。创建日期的查询字段在仪表板上设置。我有这段代码...但我似乎无法解决这个问题。
我得到了这个代码...
let container = CKContainer(identifier: "iCloud.blah")
let publicDB = container.publicCloudDatabase
// 24 hours ago
let date = NSDate(timeInterval: -60.0 * 1440, sinceDate: NSDate())
let predicate = NSPredicate(format: "creationDate < %@", date)
let query = CKQuery(recordType: "Collection", predicate: predicate)
但这可以让我获得过去 24 小时内创建的所有记录;我不想要它们,我想要所有超过 24 小时的记录。我的记录只包含一个字段,那就是一项 Assets 。开始认为这部分是我的问题......
部署后的索引大小看起来不太乐观,不是吗? 0 字节?
最佳答案
好的,我想我找到了问题的答案。这段代码很好;我的错误是在选择记录时只选择了recordID。我还需要选择元数据。
readerOperation = CKQueryOperation(查询:查询) readerOperation.desiredKeys = ["record.recordID.recordName","record.creationDate"];
readerOperation.recordFetchedBlock = { (record) in
self.records2Erase.append(record.recordID)
}
readerOperation.queryCompletionBlock = {(cursor, error) in
if error != nil {
dispatch_async(dispatch_get_main_queue()) {
self.showAlert(message: error!.localizedDescription)
}
} else {
print("records2Erase since \(date) \(self.records2Erase)")
}
}
关于swift - 获取超过 24 小时的 iCloudKit 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38060647/