---
title: "nextRecordZoneChangeBatch(_:syncEngine:)"
framework: cloudkit
role: symbol
role_heading: Instance Method
path: "cloudkit/cksyncenginedelegate-1q7g8/nextrecordzonechangebatch(_:syncengine:)"
---

# nextRecordZoneChangeBatch(_:syncEngine:)

Asks the delegate to provide the next set of record changes to send to the server.

## Declaration

```swift
func nextRecordZoneChangeBatch(_ context: CKSyncEngine.SendChangesContext, syncEngine: CKSyncEngine) async -> CKSyncEngine.RecordZoneChangeBatch?
```

## Parameters

- `context`: The reason for the sync engine’s request, and any additional options that request is using.
- `syncEngine`: The sync engine asking about pending changes.

## Return Value

Return Value If there are pending record changes, a batch of those changes for the sync engine to process; otherwise, nil to indicate there are no changes to send.

## Discussion

Discussion In your implementation, ask the sync engine’s state for any pending record zone changes and then return a change batch containing a CKRecord instance for each record identifier the state provides, as the following example shows: func nextRecordZoneChangeBatch(     _ context: CKSyncEngine.SendChangesContext,     syncEngine: CKSyncEngine ) async -> CKSyncEngine.RecordZoneChangeBatch? {

// Get the pending record changes and filter by the context's scope.     let pendingChanges = syncEngine.state.pendingRecordZoneChanges         .filter { context.options.zoneIDs.contains($0) }

// Return a change batch that contains the corresponding materialized records.     return await CKSyncEngine.RecordZoneChangeBatch(         pendingChanges: pendingChanges) { self.recordFor(id: $0) } } When syncing, you must make sure to only return a batch for the scope specified in the callback. You can do this by checking the scope property in options. If you do not do this, you may encounter a invalidArguments error. For both scheduled and manual send operations, the sync engine calls this method repeatedly until your app has no more changes and returns nil.

## See Also

### Sending changes

- [CKSyncEngine.SendChangesContext](cloudkit/cksyncengine-5sie5/sendchangescontext.md)
- [CKSyncEngine.RecordZoneChangeBatch](cloudkit/cksyncengine-5sie5/recordzonechangebatch.md)
