---
title: "endBatch(withClientState:completionHandler:)"
framework: corespotlight
role: symbol
role_heading: Instance Method
path: "corespotlight/cssearchableindex/endbatch(withclientstate:completionhandler:)"
---

# endBatch(withClientState:completionHandler:)

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

## Declaration

```swift
func endBatch(withClientState clientState: Data, completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
```

```swift
func endBatch(withClientState clientState: Data) async throws
```

## Parameters

- `clientState`: Up to 250 bytes of information that can help you recover from a crash and resume indexing.
- `completionHandler`: The block that’s called after the client state has been stored. 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)
- [endIndexBatch(expectedClientState:newClientState:completionHandler:)](corespotlight/cssearchableindex/endindexbatch(expectedclientstate:newclientstate:completionhandler:).md)
- [fetchLastClientState(completionHandler:)](corespotlight/cssearchableindex/fetchlastclientstate(completionhandler:).md)
