Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jazzedge/72dbe3e93e98703b1a5cd85c694564c1 to your computer and use it in GitHub Desktop.

Select an option

Save jazzedge/72dbe3e93e98703b1a5cd85c694564c1 to your computer and use it in GitHub Desktop.
A group of record operations may be performed in a single transaction using the CKModifyRecordsOperation class.
See: http://www.techotopia.com/index.php/An_Introduction_to_CloudKit_Data_Storage_on_iOS_8
A group of record operations may be performed in a single transaction using the
CKModifyRecordsOperation class. This class also allows timeout durations to be specified for
the transaction, together with completion handlers to be called at various stages during the
process. The following code, for example, uses the CKModifyRecordsOperation class to add three
new records and delete two existing records in a single operation. The code also establishes
timeout parameters and implements all three completion handlers. Once the modify operation
object has been created and configured, it is added to the database for execution:
let modifyRecordsOperation = CKModifyRecordsOperation(
recordsToSave: [myRecord1, myRecord2, myRecord3],
recordIDsToDelete: [myRecord4, myRecord5])
modifyRecordsOperation.timeoutIntervalForRequest = 10
modifyRecordsOperation.timeoutIntervalForResource = 10
modifyRecordsOperation.perRecordCompletionBlock = { record, error in
// Called after each individual record operation completes
}
modifyRecordsOperation.perRecordProgressBlock = { record, progress in
// Called to update the status of an indivudual operation
// progress is a Double value indicating progress so far
}
modifyRecordsOperation.modifyRecordsCompletionBlock = {
records, recordIDs, error in
// Called after all of the record operations are complete
}
privateDatabase?.add(modifyRecordsOperation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment