<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLModel/makeState()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:So7MLModelC6CoreMLE9makeStateSo7MLStateCyF"
  },
  "title" : "makeState()"
}
-->

# makeState()

Creates a new state object.

```
func makeState() -> MLState
```

## Discussion

Core ML framework will allocate the state buffers declared in the model.

The allocated state buffers are initialized to zeros. To
initialize with different values, use `.withMultiArray(for:)`
to get the mutable `MLMultiArray`-view to the state buffer.

```swift
// Create state that contains two state buffers: s1 and s2.
// Then, initialize s1 to 1.0 and s2 to 2.0.
let state = model.makeState()
state.withMultiArray(for: "s1") { stateMultiArray in
    stateMultiArray[0] = 1.0
}
state.withMultiArray(for: "s2") { stateMultiArray in
    stateMultiArray[0] = 2.0
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)