<!--
{
  "availability" : [
    "iOS: 15.4.0 -",
    "iPadOS: 15.4.0 -",
    "macCatalyst: 15.4.0 -",
    "macOS: 12.3.0 -",
    "tvOS: 15.4.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLMultiArray/withUnsafeMutableBufferPointer(ofType:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:So12MLMultiArrayC6CoreMLE30withUnsafeMutableBufferPointer6ofType_q_xm_q_SryxG_SaySiGtKXEtKAC08MLShapedB6ScalarRzr0_lF"
  },
  "title" : "withUnsafeMutableBufferPointer(ofType:_:)"
}
-->

# withUnsafeMutableBufferPointer(ofType:_:)

Calls a given closure with a raw pointer to the multiarray’s mutable storage.

```
func withUnsafeMutableBufferPointer<S, R>(ofType type: S.Type, _ body: (UnsafeMutableBufferPointer<S>, [Int]) throws -> R) rethrows -> R where S : MLShapedArrayScalar
```

## Parameters

`type`

The element type of the buffer passed in the body. This must be a Swift primitive type equivalent to `dataType`.

`body`

A closure with an <doc://com.apple.documentation/documentation/Swift/UnsafeMutableBufferPointer> parameter that points to the storage for the multiarray and its strides. This closure takes the following parameters:

- `ptr`: The pointer to the buffer.
- `strides`: The strides of the buffer in scalars. Note that this may be different from `strides`’s value prior to this method invocation.

## Discussion

The buffer contains a collection of `int32`, `float16`, `float32`, or `float64` values, depending on the multiarray’s data type. It may not store these scalar values contiguously; use `strides` to get the buffer layout.

---

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)