<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKModifyRecordsOperation",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CKModifyRecordsOperation"
  },
  "title" : "CKModifyRecordsOperation"
}
-->

# CKModifyRecordsOperation

An operation that modifies one or more records.

```
class CKModifyRecordsOperation
```

## Overview

After modifying the fields of a record, use this operation to save those changes to a database. You also use this operation to delete records permanently from a database.

If you’re saving a record that contains a reference to another record, set the reference’s [`action`](/documentation/CloudKit/CKRecord/Reference/action-swift.property) to indicate if the target record’s deletion should cascade to the saved record. This helps avoid orphaned records in explicit record hierarchies. When creating two new records that have a reference between them, use the same operation to save both records at the same time. During a save operation, CloudKit requires that the target record of the [`parent`](/documentation/CloudKit/CKRecord/parent) reference, if set, exists in the database or is part of the same operation; all other reference fields are exempt from this requirement.

When you save records, the value in the [`savePolicy`](/documentation/CloudKit/CKModifyRecordsOperation/savePolicy) property determines how to proceed when CloudKit detects conflicts. Because records can change 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 reports an error when there’s a newer version on the server. You can change the default setting to permit your changes to overwrite the server values wholly or partially.

The handlers you assign to monitor progress of the operation execute serially on an internal queue that the operation manages. You must provide handlers capable of executing on a background thread, so any tasks that require access to the main thread must redirect accordingly.

If you assign a completion handler to the <doc://com.apple.documentation/documentation/Foundation/Operation/completionBlock> property of the operation, CloudKit calls it after the operation executes and returns the results. Use the completion handler to perform any housekeeping tasks for the operation, but don’t use it to process the results of the operation. The completion handler you provide should manage any failures of the operation, whether due to an error or an explicit cancellation.

> Important: To ensure the speed of fetching and saving records, the server may reject large operations. When this occurs, a block reports the ``doc://com.apple.cloudkit/documentation/CloudKit/CKError/Code/limitExceeded`` error. Your app should handle this error, and refactor the operation into multiple smaller batches.

## Topics

### Creating a Modify Record Operation

[`init(recordsToSave:recordIDsToDelete:)`](/documentation/CloudKit/CKModifyRecordsOperation/init(recordsToSave:recordIDsToDelete:))

Creates an operation for modifying the specified records.

[`initWithRecordsToSave:recordIDsToDelete:`](/documentation/CloudKit/CKModifyRecordsOperation/initWithRecordsToSave:recordIDsToDelete:)

Creates an operation for modifying the specified records.

[`init()`](/documentation/CloudKit/CKModifyRecordsOperation/init())

Creates an empty modify records operation.

### Configuring the Modify Record Operation

[`recordsToSave`](/documentation/CloudKit/CKModifyRecordsOperation/recordsToSave)

The records to save to the database.

[`recordIDsToDelete`](/documentation/CloudKit/CKModifyRecordsOperation/recordIDsToDelete)

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

[`clientChangeTokenData`](/documentation/CloudKit/CKModifyRecordsOperation/clientChangeTokenData)

A token that tracks local changes to records.

[`isAtomic`](/documentation/CloudKit/CKModifyRecordsOperation/isAtomic)

A Boolean value that indicates whether the entire operation fails when CloudKit can’t update one or more records in a record zone.

[`savePolicy`](/documentation/CloudKit/CKModifyRecordsOperation/savePolicy)

The policy to use when saving changes to records.

[`CKModifyRecordsOperation.RecordSavePolicy`](/documentation/CloudKit/CKModifyRecordsOperation/RecordSavePolicy)

Constants that indicate which policy to apply when saving records.

### Processing the Modify Record Results

[`perRecordProgressBlock`](/documentation/CloudKit/CKModifyRecordsOperation/perRecordProgressBlock)

The closure to execute with progress information for individual records.

[`perRecordCompletionBlock`](/documentation/CloudKit/CKModifyRecordsOperation/perRecordCompletionBlock)

The closure to execute when CloudKit saves a record.

[`modifyRecordsCompletionBlock`](/documentation/CloudKit/CKModifyRecordsOperation/modifyRecordsCompletionBlock)

The closure to execute after CloudKit modifies all of the records.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)