---
title: "withMutablePixelBufferIfAvailable(_:)"
framework: coreml
role: symbol
role_heading: Instance Method
path: "coreml/mlshapedarray/withmutablepixelbufferifavailable(_:)"
---

# withMutablePixelBufferIfAvailable(_:)

Writes to the underlying pixel buffer.

## Declaration

```swift
mutating func withMutablePixelBufferIfAvailable<R>(_ body: (CVPixelBuffer) throws -> R) rethrows -> R?
```

## Parameters

- `body`: The closure to run with the pixel buffer.

## Discussion

Discussion Use this method to writes the contents of the underlying pixel buffer. let array = MLShapedArray<Float16>(mutating: pixelBuffer, shape: [2, 3]) array.withMutablePixelBuffer { backingPixelBuffer in      // write backingPixelBuffer here. }

## See Also

### Reading and writing the pixel buffer

- [withPixelBufferIfAvailable(_:)](coreml/mlshapedarray/withpixelbufferifavailable(_:).md)
