An operation that saves changes to one or more record objects.


@interface CKModifyRecordsOperation : CKDatabaseOperation


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 CKReferenceActionDeleteSelf, 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 savePolicy 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 completionBlock 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.


Initializing the Operation Object

- init

Initializes and returns an operation object.

- initWithRecordsToSave:recordIDsToDelete:

Initializes and returns an operation object configured to save and delete the specified records.

Configuring the Operation Object


The records to save to the database.


The IDs of the records to delete permanently from the database.


The policy to apply when the server contains a newer version of a specific record.


A data token used to track client-side changes to records.


A Boolean value indicating whether the entire operation fails when one or more records in the same zone cannot be written.

Processing the Operation Results


The block to execute with progress information for an individual record.


The block to execute when the save results of a single record are known.


The block to execute after the status of all changes is known.



Constants indicating the policy to apply when saving records.


Inherits From

See Also

Modifying Records


An operation that saves or deletes record zones.