<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreAI",
  "identifier" : "/documentation/CoreAI/NDArray/View/withUnsafePointer(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core AI",
      "CoreAI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime7NDArrayV4ViewV17withUnsafePointeryqd__qd__SPyxG_s4SpanVySiGAJtqd_0_YKXEqd_0_YKs5ErrorRd_0_r0_lF"
  },
  "title" : "withUnsafePointer(_:)"
}
-->

# withUnsafePointer(_:)

Invokes the provided closure with the backing data and memory layout of this view.

```
func withUnsafePointer<R, E>(_ body: (UnsafePointer<Element>, Span<Int>, Span<Int>) throws(E) -> R) throws(E) -> R where E : Error
```

## Return Value

The value returned by the closure.

## Discussion

- body: The closure to be invoked with a pointer to the first element, as well as shape and strides of the view.

> Note: This function is intended for situations where you may not be working with contiguous layouts, and as such cannot use `contiguousElements`.
> You are responsible for reading the `strides` passed in when indexing the backing data.
> If the view has an ``doc://com.apple.coreai/documentation/CoreAI/NDArray/View/interleaveLayout``, the strides for that dimension are block strides
> and must be interpreted accordingly — see ``doc://com.apple.coreai/documentation/CoreAI/NDArray/InterleaveLayout-swift.struct``.

---

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)