<!--
{
  "availability" : [
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioIONode/withAudioUnit(_:)-57kv",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "s:So13AVAudioIONodeC8AVFAudioE13withAudioUnityxxSpySo23ComponentInstanceRecordVGSgq_YKXEq_YKs5ErrorR_r0_lF"
  },
  "title" : "withAudioUnit(_:)"
}
-->

# withAudioUnit(_:)

Provides scoped access to the I/O node’s AudioUnit

```
func withAudioUnit<R, E>(_ body: (borrowing AudioUnit?) throws(E) -> R) throws(E) -> R where E : Error
```

## Parameters

`body`

A closure that receives the AudioUnit instance

## Return Value

The value returned by the closure

## Discussion

This method provides thread-safe, scoped access to the underlying AudioUnit.
The audio unit reference is only valid within the closure and must not be
retained or accessed outside of it.

> Throws: Rethrows any error thrown by the closure

---

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)