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

Creating a seamless multiview playback experience

At a glance

Item Summary
Purpose Build advanced multiview playback experiences with the AVFoundation and AVRouting frameworks.
App architecture A Swift sample with the source-visible chain MultiviewPlaybackSampleAppAppMainViewLayoutGridViewModelAVFoundation APIs.
Main patterns Model-View-ViewModel, View-controller organization, Binding-based state propagation
Project style 16 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: Sendable or @Sendable, DispatchQueue(label:), @MainActor, Task closure isolated to MainActor, Task; none alone proves a background thread.
State/event model Source-visible mechanisms: @Observable, SwiftUI state property wrapper.
Key frameworks/packages SwiftUI, os, AVFoundation, Foundation, AVKit; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── MultiviewPlaybackSampleApp/
    ├── MultiviewPlaybackSampleAppApp.swift
    ├── ViewModels/
    │   ├── MainViewModel.swift
    │   └── LayoutGridViewModel.swift
    ├── Views/
    │   ├── MainView.swift
    │   ├── GridView.swift
    │   ├── LayoutGridView.swift
    │   ├── LayoutView.swift
    │   ├── PlaybackControlsView.swift
    │   ├── PlayerView.swift
    │   └── PlayerViewController.swift
    └── Models/
        ├── Menu.swift
        └── PlayerState.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 5 project/configuration file(s) and 18 source declaration(s).

Overall architecture

Reference code

MultiviewPlaybackSampleApp/MultiviewPlaybackSampleAppApp.swift:10 — architecture anchor

@main
struct MultiviewPlaybackSampleAppApp: App {
    let mainViewModel = MainViewModel.createViewModelWithMenu

    var body: some Scene {
        WindowGroup {
            MainView(viewModel: mainViewModel)
        }
    }
}

Interpretation

The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into AVFoundation.

Ownership and state

Ownership evidence

MultiviewPlaybackSampleApp/ViewModels/MainViewModel.swift:21 — stored dependency or nearest verified ownership anchor

@Observable
class MainViewModel {
    var navigation: [MenuNavigationRoute] = []
    // ...
}
Owner Object or state Relationship Mutation authority
MainViewModel Array (navigation) owns value state App/module collaborators
MainViewModel MenuItem (menuItem) stores or receives App/module collaborators
MainViewModel MainViewModel (createViewModelWithMenu) stores or receives Initialized by the owner; the binding is immutable
LayoutGridViewModel MenuItem (selectedItem) stores or receives App/module collaborators

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.

Concurrency, scheduling, and thread safety

Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.

Concern Source mechanism Verified placement or handoff Evidence
Transfer contract Sendable or @Sendable The source declares a sendability boundary; this alone does not synchronize mutable state. MultiviewPlaybackSampleApp/Models/Menu.swift:11
Queue scheduling DispatchQueue(label:) The source constructs a dispatch queue; its label alone does not prove a thread. MultiviewPlaybackSampleApp/Models/PlayerState.swift:28
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. MultiviewPlaybackSampleApp/Models/PlayerState.swift:182
Main isolation Task closure isolated to MainActor The cited operation explicitly enters a main-actor-isolated region. MultiviewPlaybackSampleApp/Models/PlayerState.swift:182
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. MultiviewPlaybackSampleApp/Models/PlayerState.swift:182

@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.

Reference code

MultiviewPlaybackSampleApp/Models/Menu.swift:11 — representative execution boundary

typealias DataModel = (Codable & Equatable & Sendable)

State propagation, frameworks, and dependencies

Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.

Category Mechanism or module Verified role Evidence
State propagation @Observable Observation macro publishes source-visible changes. MultiviewPlaybackSampleApp/Models/PlayerState.swift:15
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. MultiviewPlaybackSampleApp/Views/GridView.swift:15
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. MultiviewPlaybackSampleApp/MultiviewPlaybackSampleAppApp.swift:8
Source import os The cited file imports this module; runtime use and architectural role are not inferred. MultiviewPlaybackSampleApp/Models/PlayerState.swift:11
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. MultiviewPlaybackSampleApp/Models/Menu.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. MultiviewPlaybackSampleApp/Models/Menu.swift:8
Source import AVKit The cited file imports this module; runtime use and architectural role are not inferred. MultiviewPlaybackSampleApp/Views/PlayerViewController.swift:10
Source import AVRouting The cited file imports this module; runtime use and architectural role are not inferred. MultiviewPlaybackSampleApp/Models/PlayerState.swift:12

receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.

Class and protocol design

MultiviewPlaybackSampleApp/MultiviewPlaybackSampleAppApp.swift:11 — representative type boundary

@main
struct MultiviewPlaybackSampleAppApp: App {
    let mainViewModel = MainViewModel.createViewModelWithMenu
    // ...
}
Type Responsibility Depends on or conforms to
MultiviewPlaybackSampleAppApp Application entry and top-level composition App
MainViewModel UI-facing state and feature coordination Concrete collaborators/imported frameworks
LayoutGridViewModel UI-facing state and feature coordination Concrete collaborators/imported frameworks
MainView User-interface presentation and input forwarding View
GridView User-interface presentation and input forwarding View
LayoutGridView User-interface presentation and input forwarding View
LayoutView User-interface presentation and input forwarding View
PlaybackControlsView User-interface presentation and input forwarding View
PlayerView User-interface presentation and input forwarding View
PlayerViewController View lifecycle, callbacks, and feature coordination UIViewControllerRepresentable

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
queue (MultiviewPlaybackSampleApp/Models/PlayerState.swift:28) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
PlayerViewController (MultiviewPlaybackSampleApp/Views/PlayerViewController.swift:16) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
LayoutGridViewModel (MultiviewPlaybackSampleApp/ViewModels/LayoutGridViewModel.swift:8) implicit internal No explicit modifier means the Swift declaration is internal to the module. Inference: app-target collaboration needs no exported library surface.

Reference code

MultiviewPlaybackSampleApp/Models/PlayerState.swift:28 — representative boundary

@Observable
class PlayerState {
    // ...
    private let queue = DispatchQueue(label: "com.apple.AVFoundation.MultiviewPlaybackSampleApp.PlayerState.queue")
    // ...
}

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
Application entry and top-level composition MultiviewPlaybackSampleAppApp The source’s App suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination PlayerViewController The source’s Controller suffix makes this role explicit.
User-interface presentation and input forwarding GridView, LayoutGridView, LayoutView, MainView The source’s View suffix makes this role explicit.
UI-facing state and feature coordination LayoutGridViewModel, MainViewModel The source’s ViewModel suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Model-View-ViewModel MultiviewPlaybackSampleApp/ViewModels/LayoutGridViewModel.swift:13 Role-named view models keep UI-facing state or coordination outside view declarations.
View-controller organization MultiviewPlaybackSampleApp/Views/PlayerViewController.swift:13 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Binding-based state propagation MultiviewPlaybackSampleApp/Views/LayoutGridView.swift:15 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: App: MultiviewPlaybackSampleAppApp; Controller: PlayerViewController; View: GridView, LayoutGridView, LayoutView, MainView, PlaybackControlsView; ViewModel: LayoutGridViewModel, MainViewModel.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: showGridView, showLayoutView, updateValuesFromMenuItem, resetStates, invalidate, resetValues, createAllPlayers, updateLayoutGridValues.
  • Files: MultiviewPlaybackSampleApp/MultiviewPlaybackSampleAppApp.swift, MultiviewPlaybackSampleApp/ViewModels/MainViewModel.swift, MultiviewPlaybackSampleApp/ViewModels/LayoutGridViewModel.swift, MultiviewPlaybackSampleApp/Views/MainView.swift, MultiviewPlaybackSampleApp/Models/Menu.swift, MultiviewPlaybackSampleApp/Views/GridView.swift.

Architecture takeaways

  • MultiviewPlaybackSampleAppApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, AVFoundation, AVKit, AVRouting 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.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
MultiviewPlaybackSampleApp/MultiviewPlaybackSampleAppApp.swift Cited implementation, MultiviewPlaybackSampleAppApp, SwiftUI
MultiviewPlaybackSampleApp/ViewModels/MainViewModel.swift Cited implementation, MenuNavigationRoute, MainViewModel
MultiviewPlaybackSampleApp/Models/PlayerState.swift Cited implementation, DispatchQueue(label:), @MainActor, Task closure isolated to MainActor, Task, @Observable, os, AVRouting, PlayerState
MultiviewPlaybackSampleApp/Views/PlayerViewController.swift Cited implementation, PlayerViewController, AVKit
MultiviewPlaybackSampleApp/ViewModels/LayoutGridViewModel.swift LayoutGridViewModel
MultiviewPlaybackSampleApp/Views/LayoutGridView.swift Cited implementation, LayoutGridView
MultiviewPlaybackSampleApp/Models/Menu.swift Sendable or @Sendable, AVFoundation, Foundation, Menu, MenuItem, MenuAsset, NetworkPriority
MultiviewPlaybackSampleApp/Views/GridView.swift SwiftUI state property wrapper, GridView
MultiviewPlaybackSampleApp/Views/MainView.swift MainView
MultiviewPlaybackSampleApp/Views/LayoutView.swift LayoutView
MultiviewPlaybackSampleApp/Views/PlaybackControlsView.swift PlaybackControlsView
MultiviewPlaybackSampleApp/Views/PlayerView.swift PlayerView
MultiviewPlaybackSampleApp/Utilities/Extensions/Bundle+Additions.swift DecodingError
MultiviewPlaybackSampleApp/Utilities/SelectionButtonStyle.swift SelectionButtonStyle
MultiviewPlaybackSampleApp/Utilities/Extensions/Logger+Additions.swift Feature implementation
MultiviewPlaybackSampleApp/Utilities/Extensions/URL+Additions.swift Feature implementation