Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Displaying video from connected devices

At a glance

Item Summary
Purpose Show video from devices connected with the Developer Strap in your visionOS app.
App architecture A Swift sample with the source-visible chain DisplayConnectedVideoAppContentViewCaptureManagerAVFoundation / SwiftUI APIs.
Main patterns Delegate or data-source callbacks, Actor isolation
Project style 6 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: actor, Task, await suspension point, @MainActor; none alone proves a background thread.
State/event model Source-visible mechanisms: NotificationCenter, SwiftUI state property wrapper, @Observable.
Key frameworks/packages AVFoundation, SwiftUI; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── DisplayConnectedVideo/
│   ├── DisplayConnectedVideoApp.swift
│   ├── ConnectionManager.swift
│   ├── CaptureManager.swift
│   ├── ContentView.swift
│   ├── DeviceManager.swift
│   ├── DevicePreview.swift
│   └── Info.plist
├── Configuration/
│   └── SampleCode.xcconfig
└── DisplayConnectedVideo.xcodeproj/
    ├── .xcodesamplecode.plist
    └── project.pbxproj

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 4 project/configuration file(s) and 8 source declaration(s).

Overall architecture

Reference code

DisplayConnectedVideo/DisplayConnectedVideoApp.swift:10 — architecture anchor

@main
struct DisplayConnectedVideoApp: App {
    var body: some Scene {

        WindowGroup {
            ContentView()
        }
     }
}

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 visionOS.

Ownership and state

Ownership evidence

DisplayConnectedVideo/ConnectionManager.swift:16 — stored dependency or nearest verified ownership anchor

struct Device: Identifiable, Hashable {
    let id: String
    // ...
}
Owner Object or state Relationship Mutation authority
Device String (id) owns value state Initialized by the owner; the binding is immutable
Device String (name) owns value state Initialized by the owner; the binding is immutable
ConnectionManager AsyncStream (devices) stores or receives Initialized by the owner; the binding is immutable
ConnectionManager AsyncStream (continuation) stores or receives Owning lexical scope

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
Actor isolation actor The cited type is actor-isolated; this does not select a background thread. DisplayConnectedVideo/CaptureManager.swift:10
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. DisplayConnectedVideo/CaptureManager.swift:30
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. DisplayConnectedVideo/CaptureManager.swift:32
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. DisplayConnectedVideo/ConnectionManager.swift:26

@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

DisplayConnectedVideo/CaptureManager.swift:10 — representative execution boundary

actor CaptureManager: NSObject {
    private let captureSession = AVCaptureSession()
    // ...
}

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 NotificationCenter NotificationCenter distributes named process-local events. DisplayConnectedVideo/CaptureManager.swift:99
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. DisplayConnectedVideo/ContentView.swift:12
State propagation @Observable Observation macro publishes source-visible changes. DisplayConnectedVideo/DeviceManager.swift:11
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. DisplayConnectedVideo/CaptureManager.swift:8
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. DisplayConnectedVideo/ContentView.swift:8

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

DisplayConnectedVideo/DisplayConnectedVideoApp.swift:11 — representative type boundary

@main
struct DisplayConnectedVideoApp: App {
    // ...
            ContentView()
    // ...
}
Type Responsibility Depends on or conforms to
DisplayConnectedVideoApp Application entry and top-level composition App
ConnectionManager Long-lived feature or framework coordination Concrete collaborators/imported frameworks
CaptureManager Long-lived feature or framework coordination NSObject
ContentView User-interface presentation and input forwarding View
DeviceManager Long-lived feature or framework coordination Concrete collaborators/imported frameworks
Device Represents a feature value or composable behavior Identifiable, Hashable
DevicePreview Represents a feature value or composable behavior UIViewRepresentable
SampleBufferPreview Owns feature behavior and collaborator lifecycle UIView

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
captureSession (DisplayConnectedVideo/CaptureManager.swift:11) 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.
videoDataOutput (DisplayConnectedVideo/CaptureManager.swift:12) 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.
sessionQueue (DisplayConnectedVideo/CaptureManager.swift:14) 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.
setUpSession (DisplayConnectedVideo/CaptureManager.swift:37) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.

Reference code

DisplayConnectedVideo/CaptureManager.swift:11 — representative boundary

actor CaptureManager: NSObject {
    private let captureSession = AVCaptureSession()
    // ...
}

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 DisplayConnectedVideoApp The source’s App suffix makes this role explicit.
Long-lived feature or framework coordination CaptureManager, ConnectionManager, DeviceManager The source’s Manager suffix makes this role explicit.
User-interface presentation and input forwarding ContentView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks DisplayConnectedVideo/CaptureManager.swift:108 Callback protocols invert event delivery back into the sample’s owner.
Actor isolation DisplayConnectedVideo/CaptureManager.swift:10 A declared actor creates an explicit isolation boundary; its executor is not described as a background thread.

Main application flow

Reference code

DisplayConnectedVideo/DeviceManager.swift:53init()

    init() {
        // Create the capture manager passing it the object to enqueue sample buffers for rendering.
        captureManager = CaptureManager(videoRenderer: preview.sampleBufferRenderer)

        initialAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)

        Task {
            if initialAuthorizationStatus == .notDetermined {
                await AVCaptureDevice.requestAccess(for: .video)

                initialAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
            }
        }

        Task {
            // Monitor updates to the device list.
            for await devices in connectionManager.devices {
                self.devices = devices
            }
        }
    }

Naming conventions

  • Types: App: DisplayConnectedVideoApp; Manager: CaptureManager, ConnectionManager, DeviceManager; View: ContentView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: observeDeviceConnectionStates, updateDeviceList, setUpSession, select, start, observeFlushToResumeDecoding, captureOutput, makeUIView.
  • Files: DisplayConnectedVideo/DisplayConnectedVideoApp.swift, DisplayConnectedVideo/ConnectionManager.swift, DisplayConnectedVideo/CaptureManager.swift, DisplayConnectedVideo/ContentView.swift, DisplayConnectedVideo/DeviceManager.swift, DisplayConnectedVideo/DevicePreview.swift.

Architecture takeaways

  • DisplayConnectedVideoApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches AVFoundation, SwiftUI 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
DisplayConnectedVideo/DisplayConnectedVideoApp.swift Cited implementation, DisplayConnectedVideoApp
DisplayConnectedVideo/ConnectionManager.swift Cited implementation, @MainActor, Device, ConnectionManager
DisplayConnectedVideo/CaptureManager.swift Cited implementation, CaptureManager, actor, Task, await suspension point, NotificationCenter, AVFoundation
DisplayConnectedVideo/ContentView.swift SwiftUI state property wrapper, SwiftUI, ContentView
DisplayConnectedVideo/DeviceManager.swift @Observable, DeviceManager
DisplayConnectedVideo/DevicePreview.swift DevicePreview, SampleBufferPreview