---
title: "endIndexBatch(expectedClientState:newClientState:completionHandler:)"
framework: corespotlight
role: symbol
role_heading: Instance Method
path: "corespotlight/cssearchableindex/endindexbatch(expectedclientstate:newclientstate:completionhandler:)"
---

# endIndexBatch(expectedClientState:newClientState:completionHandler:)

Ends a batch of index updates and stores the specified state information.

## Declaration

```swift
func endIndexBatch(expectedClientState: Data?, newClientState: Data, completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
```

```swift
func endIndexBatch(expectedClientState: Data?, newClientState: Data) async throws
```

## Parameters

- `expectedClientState`: The client state data from the previous batch.
- `newClientState`: Up to 250 bytes of app-specific data that can help you recover from a crash and resume indexing.
- `completionHandler`: The block to call with the results. The block receives the following parameter:

## Discussion

Discussion important: You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration: func endBatch(withClientState clientState: Data) async throws For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously.

## See Also

### Batching index updates

- [beginBatch()](corespotlight/cssearchableindex/beginbatch().md)
- [endBatch(withClientState:completionHandler:)](corespotlight/cssearchableindex/endbatch(withclientstate:completionhandler:).md)
- [fetchLastClientState(completionHandler:)](corespotlight/cssearchableindex/fetchlastclientstate(completionhandler:).md)
