Class

CKModifyRecordsOperation

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

Declaration

class CKModifyRecordsOperation : CKDatabaseOperation

Overview

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_Reference_Action.deleteSelf, 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.

Topics

Initializing the Operation Object

init()

Initializes and returns an operation object.

Configuring the Operation Object

var recordsToSave: [CKRecord]?

The records to save to the database.

var recordIDsToDelete: [CKRecord.ID]?

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

var savePolicy: CKModifyRecordsOperation.RecordSavePolicy

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

var clientChangeTokenData: Data?

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

var isAtomic: Bool

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

var perRecordProgressBlock: ((CKRecord, Double) -> Void)?

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

var perRecordCompletionBlock: ((CKRecord, Error?) -> Void)?

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

var modifyRecordsCompletionBlock: (([CKRecord]?, [CKRecord.ID]?, Error?) -> Void)?

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

Constants

enum CKModifyRecordsOperation.RecordSavePolicy

Constants indicating the policy to apply when saving records.

Relationships

Inherits From

Conforms To

See Also

Modifying Records

class CKModifyRecordZonesOperation

An operation that saves or deletes record zones.