---
title: "withUnsafeBufferPointer(ofType:_:)"
framework: coreml
role: symbol
role_heading: Instance Method
path: "coreml/mlmultiarray/withunsafebufferpointer(oftype:_:)"
---

# withUnsafeBufferPointer(ofType:_:)

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

## Declaration

```swift
func withUnsafeBufferPointer<S, R>(ofType type: S.Type, _ body: (UnsafeBufferPointer<S>) 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. This closure takes the following parameter:
- `body`: A closure with an doc://com.apple.documentation/documentation/Swift/UnsafeBufferPointer parameter that points to the storage for the multiarray.

## Discussion

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.

## See Also

### Providing buffer access

- [withUnsafeBytes(_:)](coreml/mlmultiarray/withunsafebytes(_:).md)
- [withUnsafeMutableBufferPointer(ofType:_:)](coreml/mlmultiarray/withunsafemutablebufferpointer(oftype:_:).md)
- [withUnsafeMutableBytes(_:)](coreml/mlmultiarray/withunsafemutablebytes(_:).md)
