---
title: "enumerate(_:batchSize:allowEscapingMutations:block:)"
framework: swiftdata
role: symbol
role_heading: Instance Method
path: "swiftdata/modelcontext/enumerate(_:batchsize:allowescapingmutations:block:)"
---

# enumerate(_:batchSize:allowEscapingMutations:block:)

Runs a closure for each model that matches the criteria of the specified fetch descriptor.

## Declaration

```swift
func enumerate<T>(_ fetch: FetchDescriptor<T>, batchSize: Int = 5000, allowEscapingMutations: Bool = false, block: (T) throws -> Void) throws where T : PersistentModel
```

## Parameters

- `fetch`: A fetch descriptor that provides the configuration for the fetch.
- `batchSize`: The maximum number of models to include in each batch. The default value is 5000.
- `allowEscapingMutations`: A Boolean value that determines whether the closure can leave the context in a modified state after it completes. The default value is false.
- `block`: The closure to run for each fetched model.

## See Also

### Fetching models

- [fetch(_:)](swiftdata/modelcontext/fetch(_:).md)
- [fetch(_:batchSize:)](swiftdata/modelcontext/fetch(_:batchsize:).md)
- [fetchCount(_:)](swiftdata/modelcontext/fetchcount(_:).md)
- [FetchDescriptor](swiftdata/fetchdescriptor.md)
- [FetchResultsCollection](swiftdata/fetchresultscollection.md)
- [model(for:)](swiftdata/modelcontext/model(for:).md)
- [registeredModel(for:)](swiftdata/modelcontext/registeredmodel(for:).md)
