I'm trying to download a batch of records from my iCloud public database using CloudKit and the cursor. The code works fine for the first 3 executions, regardless of how the resultsLimit is set, but the 4th completion block is never executed. If resultsLimit is not set I get 300 records, if it's set to 50 I get 150, if it's set to 5 I get 15...
No error is reported and the block appears to be added but is never executed. Platform is OS X. Here's the code in question:
let queryOp = CKQueryOperation(query: query)
queryOp.recordFetchedBlock = self.fetchedDetailRecord
queryOp.resultsLimit = 5
queryOp.queryCompletionBlock = { [weak self]
(cursor: CKQueryCursor!, error: NSError!) -> Void in
println("comp block called with \(cursor) \(error)")
if error != nil {
println("Error on fetch \(error.userInfo)")
} else {
if cursor != nil {
let nextOp = CKQueryOperation(cursor: cursor)
nextOp.recordFetchedBlock = self!.fetchedDetailRecord
nextOp.queryCompletionBlock = queryOp.queryCompletionBlock
nextOp.resultsLimit = 5
self!.publicDatabase?.addOperation(nextOp)
println("added next fetch")
} else {
self!.fileHandle!.closeFile()
self!.exportProgressIndicator.stopAnimation(self)
}
}
}
self.publicDatabase?.addOperation(queryOp)
And here's the results from the console -
459013587628.012 0 459013587628.621 1 459013587628.863 2 459013587629.113 3 459013587629.339 4 comp block called with nil added next fetch 459013587828.552 5 459013587828.954 6 459013587829.198 7 459013587829.421 8 459013587829.611 9 comp block called with nil added next fetch 459013587997.084 10 459013587997.479 11 459013587997.74 12 459013587997.98 13 459013587998.207 14
The big number is just the time between calls to the recordFetchedBlock with the second number being the count of times that block has been called.
I'm stumped...any ideas on how to proceed? Oh, container and publicDatabase are class variables and initialized prior to running the code snippet above.