Reputation: 1
I am working with CloudKit and attempting to fectch records by "modificationDate" but will populate my results limit starting with the oldest. For instance, if I have 4 records created mon, tues, wed, thurs and I select just two of them, I would get the mon, tues record and not the wed thurs. Below is the code that I am trying to fix.
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)
}
I figured it would be as simple as flagging the NSSortDescriptor
ascending to false. But this did not work (after more testing I found that this will return only records that have a value of 0 for a selected field).
Additionally I tried some various predicate comparisons to no avail. Any thoughts? I'm about ready to give up on CloudKit forever.
Upvotes: 0
Views: 268