An operation that saves changes to one or more record objects.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 3.0+
After modifying the fields of a record, use this type of operation object to save those changes to a database. You also use instances of this class to delete records permanently from a database.
When saving a record that contains a reference whose action is
CKRecord, CloudKit must be able to find the target of the reference. During a save operation, CloudKit verifies that any target records actually exist in the database. If it cannot verify the existence of a target record, CloudKit reports an error and does not save the record containing the reference to that target. When creating two new records that have a reference between them, use the same operation object to save both records at the same time.
When you save records, the value in the
save property determines how to proceed when conflicts are detected on the server. Because records can be modified between the time you fetch them and the time you save them, the save policy determines whether new changes overwrite existing changes. By default, the operation object reports an error if a newer version of a record is found on the server. You can change the default setting to permit your changes to overwrite the server values wholly or partially.
The blocks you assign to monitor progress of the operation are executed serially on an internal queue managed by the operation object. Your blocks must be capable of executing on a background thread, so any tasks that require access to the main thread must be redirected accordingly.
If you assign a completion block to the
completion property of the operation object, the completion block is called after the operation executes and returns its results to you. You can use a completion block to perform housekeeping chores related to the operation, but do not use it to process the results of the operation itself. Any completion block you specify should be prepared to handle the failure of the operation to complete its task, whether due to an error or an explicit cancellation.