Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-21View on Apple Developer

Incorporating Audio Effects and Instruments

At a glance

Item Summary
Purpose Add custom audio processing and MIDI instruments to your app by hosting Audio Unit (AU) plug-ins.
App architecture A Swift sample bundle with entry-bearing project variants iOS, macOS, each leading to Cocoa / UIKit APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Coordinator
Project style 12 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── Shared/
│   ├── AudioUnitManager.swift
│   └── Support/
│       ├── SimplePlayEngine.swift
│       └── ViewExtensions.swift
├── macOS/
│   └── AUv3Host/
│       ├── MainViewController.swift
│       ├── AppDelegate.swift
│       ├── ComponentViewController.swift
│       ├── ListViewController.swift
│       ├── PresetsViewController.swift
│       ├── SaveSheetViewController.swift
│       └── AlertExtensions.swift
└── iOS/
    └── AUv3Host/
        ├── AppDelegate.swift
        └── MainViewController.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: Swift.
  • The verified tree contains 8 project/configuration file(s) and 22 source declaration(s).

Overall architecture

Reference code

iOS/AUv3Host/AppDelegate.swift:10 — architecture anchor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

}

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

Shared/AudioUnitManager.swift:45 — stored dependency or nearest verified ownership anchor

struct UserPresetsChange {
    let type: UserPresetsChangeType
    let userPresets: [Preset]
}
Owner Object or state Relationship Mutation authority
UserPresetsChange UserPresetsChangeType (type) stores or receives Initialized by the owner; the binding is immutable
UserPresetsChange Array (userPresets) owns value state Initialized by the owner; the binding is immutable
UserPresetsChange Notification (userPresetsChanged) stores or receives Initialized by the owner; the binding is immutable
Preset AUAudioUnitPreset (audioUnitPreset) stores or receives Initialized by the owner; the binding is immutable

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Class and protocol design

macOS/AUv3Host/MainViewController.swift:10 — representative type boundary

protocol Coordinator: AnyObject {
    // ...
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate
Coordinator Defines a capability or collaboration contract AnyObject
Component Stores entity-component data or behavior Concrete collaborators/imported frameworks
AudioUnitManager Long-lived feature or framework coordination Concrete collaborators/imported frameworks
MainViewController View lifecycle, callbacks, and feature coordination NSSplitViewController
SplitView User-interface presentation and input forwarding NSSplitView
BarView User-interface presentation and input forwarding NSView
SimplePlayEngine Owns processing or simulation work Concrete collaborators/imported frameworks
InstrumentPlayer Owns media or timeline playback Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: MainViewControllerCoordinator.

Access control

Symbol Access Verified effect Likely rationale
AudioUnitManager (Shared/AudioUnitManager.swift:61) fileprivate Use is restricted to this source file. Inference: share with same-file helpers or extensions without exposing the symbol module-wide.
audioUnitPreset (Shared/AudioUnitManager.swift:64) fileprivate Use is restricted to this source file. Inference: share with same-file helpers or extensions without exposing the symbol module-wide.
number (Shared/AudioUnitManager.swift:65) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
name (Shared/AudioUnitManager.swift:66) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.

Reference code

Shared/AudioUnitManager.swift:61 — representative boundary

    fileprivate init(preset: AUAudioUnitPreset) {
        audioUnitPreset = preset
    }
    fileprivate let audioUnitPreset: AUAudioUnitPreset
    public var number: Int { return audioUnitPreset.number }
    public var name: String { return audioUnitPreset.name }

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
Stores entity-component data or behavior Component The source’s Component suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination ComponentViewController, ListViewController, MainViewController, PresetsViewController The source’s Controller suffix makes this role explicit.
Cross-object flow or session coordination Coordinator The source’s Coordinator suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.
Owns processing or simulation work SimplePlayEngine The source’s Engine suffix makes this role explicit.
Long-lived feature or framework coordination AudioUnitManager The source’s Manager suffix makes this role explicit.
Owns media or timeline playback InstrumentPlayer The source’s Player suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization macOS/AUv3Host/ComponentViewController.swift:10 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction macOS/AUv3Host/MainViewController.swift:22 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks iOS/AUv3Host/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.
Coordinator macOS/AUv3Host/MainViewController.swift:10 A role-named coordinator centralizes cross-object flow.

Naming conventions

  • Types: Component: Component; Controller: ComponentViewController, ListViewController, MainViewController, PresetsViewController, SaveSheetViewController; Coordinator: Coordinator; Delegate: AppDelegate; Engine: SimplePlayEngine; Manager: AudioUnitManager; Player: InstrumentPlayer; View: BarView, SplitView.
  • Protocols: Coordinator.
  • Methods: requestGenericViewController, requestViewController, savePreset, deletePreset, toggleViewMode, loadAudioUnits, selectComponent, loadAudioUnitViewController.
  • Files: Shared/AudioUnitManager.swift, macOS/AUv3Host/MainViewController.swift, iOS/AUv3Host/AppDelegate.swift, macOS/AUv3Host/AppDelegate.swift, Shared/Support/SimplePlayEngine.swift, iOS/AUv3Host/MainViewController.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Cocoa, UIKit, AVFoundation, AppKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • Local protocol relationships provide an explicit substitution boundary.

Source map

Source file Relevant symbols
Shared/AudioUnitManager.swift AudioUnitType, InstantiationType, PresetType, UserPresetsChangeType, UserPresetsChange, Preset, Component, AudioUnitManager
macOS/AUv3Host/MainViewController.swift Coordinator, MainViewController, SplitView, BarView, ToggleToolbarItem
iOS/AUv3Host/AppDelegate.swift AppDelegate
macOS/AUv3Host/AppDelegate.swift AppDelegate
Shared/Support/SimplePlayEngine.swift SimplePlayEngine, InstrumentPlayer
iOS/AUv3Host/MainViewController.swift MainViewController, func
macOS/AUv3Host/ComponentViewController.swift ComponentViewController
macOS/AUv3Host/ListViewController.swift ListViewController
macOS/AUv3Host/PresetsViewController.swift PresetsViewController
macOS/AUv3Host/SaveSheetViewController.swift SaveSheetViewController