Skip to content

Instantly share code, notes, and snippets.

@MarcusSmith
Created February 22, 2016 21:59
Show Gist options
  • Save MarcusSmith/89643ad257d689ca2348 to your computer and use it in GitHub Desktop.
Save MarcusSmith/89643ad257d689ca2348 to your computer and use it in GitHub Desktop.
Retrieve persisted long-lived operations, reassign their completion blocks and add them back to a CKDatabase
CKContainer.defaultContainer().fetchAllLongLivedOperationIDsWithCompletionHandler { (operationIDs, error) in
guard let operationIDs = operationIDs else {
print("error:", error)
return
}
operationIDs.forEach { (operationID) in
CKContainer.defaultContainer().fetchLongLivedOperationWithID(operationID) { (operation, error) in
guard let operation = operation else {
print("Unable to fetch operation with ID", operationID, "error:", error)
return
}
if let modifyOperation = operation as? CKModifyRecordsOperation {
modifyOperation.modifyRecordsCompletionBlock = { (savedRecords, _, error) in
print("Operation with ID", operation.operationID, "saved records", savedRecords, "error", error)
}
CKContainer.defaultContainer().publicCloudDatabase.addOperation(modifyOperation)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment