---
title: MLState
framework: coreml
role: symbol
role_heading: Class
path: coreml/mlstate
---

# MLState

Handle to the state buffers.

## Declaration

```swift
class MLState
```

## Overview

Overview A stateful model maintains a state from one prediction to another by storing the information in the state buffers. To use such a model, the client must request the model to create state buffers and get MLState object, which is the handle to those buffers. Then, at the prediction time, pass the MLState object in one of the stateful prediction functions. // Load a stateful model let modelAsset = try MLModelAsset(url: modelURL) let model = try await MLModel.load(asset: modelAsset, configuration: MLModelConfiguration())

// Request a state let state = model.newState()

// Run predictions for _ in 0 ..< 42 {   _ = try await model.prediction(from: inputFeatures, using: state) }

// Access the state buffer. state.withMultiArray(for: "accumulator") { stateMultiArray in   ... } The object is a handle to the state buffers. The client shall not read or write the buffers while a prediction is in-flight. Each stateful prediction that uses the same MLState must be serialized. Otherwise, if two such predictions run concurrently, the behavior is undefined.

## Topics

### Getting a state buffer

- [withMultiArray(for:_:)](coreml/mlstate/withmultiarray(for:_:).md)
- [withMultiArray(_:)](coreml/mlstate/withmultiarray(_:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Model state

- [MLStateConstraint](coreml/mlstateconstraint.md)
