Created
February 22, 2016 20:08
-
-
Save MarcusSmith/839ae5d08bfab5db3c73 to your computer and use it in GitHub Desktop.
CKQueryOperation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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