Skip to content

Instantly share code, notes, and snippets.

@MarcusSmith
Created February 22, 2016 20:08
Show Gist options
  • Save MarcusSmith/839ae5d08bfab5db3c73 to your computer and use it in GitHub Desktop.
Save MarcusSmith/839ae5d08bfab5db3c73 to your computer and use it in GitHub Desktop.
CKQueryOperation
var allRecords: [CKRecord] = []
let operation = CKQueryOperation(query: query)
operation.recordFetchedBlock = { (record: CKRecord) in
allRecords.append(record)
}
operation.queryCompletionBlock = { (cursor: CKQueryCursor?, error: NSError?) in
// There is another batch of records to be fetched
if let cursor = cursor {
let newOperation = CKQueryOperation(cursor: cursor)
newOperation.recordFetchedBlock = operation.recordFetchedBlock
newOperation.queryCompletionBlock = operation.queryCompletionBlock
database.addOperation(newOperation)
}
// There was an error
else if let error = error {
print("Error:", error)
}
// No error and no cursor means the operation was successful
else {
print("Finished with records:", allRecords)
}
}
database.addOperation(operation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment