我正在使用 CloudKit 并尝试通过“modificationDate”来完善记录,但将从最旧的开始填充我的结果限制。例如,如果我在周一、周二、周三、周四创建了 4 条记录,而我只选择其中两条,我将获得周一、周二的记录,而不是周三的周四。下面是我要修复的代码。
func fetchRecentModified() {
let predicate = NSPredicate(value: true)
let sort = NSSortDescriptor(key: "votes", ascending: true)
let query = CKQuery(recordType: "Dog", predicate: predicate)
query.sortDescriptors = [sort]
let operation = CKQueryOperation(query: query)
operation.resultsLimit = recordFetchMax
operation.recordFetchedBlock = { (record) in
VoteQueue.sharedInstance.append(record)
}
operation.queryCompletionBlock = { (cursor, error) in
dispatch_async(dispatch_get_main_queue()) {
if error == nil {
print("There is no error fetching records \(recordFetchMax)")
print(VoteQueue.sharedInstance)
API.shared.flagRecords(VoteQueue.sharedInstance)
} else {
print("There was a problem fetching the list of dogs please try again")
print(error)
}
}
}
self.database.addOperation(operation)
}
我认为这就像将NSSortDescriptor
升序标记为 false 一样简单。但这不起作用(经过更多测试,我发现这将只返回所选字段值为 0 的记录)。
此外,我尝试了一些各种谓词比较无济于事。有什么想法吗?我准备永远放弃 CloudKit。