---
title: "modifyRecords(saving:deleting:savePolicy:atomically:completionHandler:)"
framework: cloudkit
role: symbol
role_heading: Instance Method
path: "cloudkit/ckdatabase/modifyrecords(saving:deleting:savepolicy:atomically:completionhandler:)"
---

# modifyRecords(saving:deleting:savePolicy:atomically:completionHandler:)

Modifies the specified records and delivers the results to a completion hander.

## Declaration

```swift
@preconcurrency func modifyRecords(saving recordsToSave: [CKRecord], deleting recordIDsToDelete: [CKRecord.ID], savePolicy: CKModifyRecordsOperation.RecordSavePolicy = .ifServerRecordUnchanged, atomically: Bool = true, completionHandler: @escaping @Sendable (Result<(saveResults: [CKRecord.ID : Result<CKRecord, any Error>], deleteResults: [CKRecord.ID : Result<Void, any Error>]), any Error>) -> Void)
```

## Parameters

- `recordsToSave`: The records to save.
- `recordIDsToDelete`: The identifiers of the records to permanently delete.
- `savePolicy`: The policy to use when modifying existing records. For possible values, see doc://com.apple.cloudkit/documentation/CloudKit/CKModifyRecordsOperation/RecordSavePolicy.
- `atomically`: If doc://com.apple.documentation/documentation/Swift/true, the entire operation fails if CloudKit can’t modify one or more of the specified records; otherwise, CloudKit reports individual failures in the returned tuple. Atomic changes are only applicable in record zones that have the doc://com.apple.cloudkit/documentation/CloudKit/CKRecordZone/Capabilities-swift.struct/atomic capability.
- `completionHandler`: The closure to execute after CloudKit processes the changes.

## Discussion

Discussion The completion handler takes a single Result parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn’t have an active iCloud account, or when atomically is true and one or more of the specified changes fail. When present, the tuple contains the following named elements: Deleting records may cause additional deletions if other records in the database reference the deleted records. CloudKit doesn’t provide the identifiers of any additional records it deletes. For information on a more configurable way to modify records, see CKModifyRecordsOperation.

## See Also

### Modifying Records

- [modifyRecords(saving:deleting:savePolicy:atomically:)](cloudkit/ckdatabase/modifyrecords(saving:deleting:savepolicy:atomically:).md)
- [CKModifyRecordsOperation.RecordSavePolicy](cloudkit/ckmodifyrecordsoperation/recordsavepolicy.md)
- [save(_:completionHandler:)](cloudkit/ckdatabase/save(_:completionhandler:)-3tatz.md)
- [delete(withRecordID:completionHandler:)](cloudkit/ckdatabase/delete(withrecordid:completionhandler:).md)
