<!--
{
  "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/withUnsafeMutableBytes(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:So12MLMultiArrayC6CoreMLE22withUnsafeMutableBytesyxxSw_SaySiGtKXEKlF"
  },
  "title" : "withUnsafeMutableBytes(_:)"
}
-->

# withUnsafeMutableBytes(_:)

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

```
func withUnsafeMutableBytes<R>(_ body: (UnsafeMutableRawBufferPointer, [Int]) throws -> R) rethrows -> R
```

## Parameters

`body`

A closure with an <doc://com.apple.documentation/documentation/Swift/UnsafeMutableRawBufferPointer> 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)