Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Creating a foveated streaming client on visionOS

At a glance

Item Summary
Purpose Build a visionOS app that streams high-fidelity immersive content from a computer or the cloud using the Foveated Streaming framework.
App architecture A Swift sample with the source-visible chain FoveatedStreamingSampleAppContentViewAppModelFoveatedStreaming / FoveatedStreamingSimulator APIs.
Main patterns Binding-based state propagation
Project style 14 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: await suspension point, @MainActor, Task closure isolated to MainActor, Task, Sendable or @Sendable; none alone proves a background thread.
State/event model Source-visible mechanisms: @Observable, SwiftUI state property wrapper.
Key frameworks/packages SwiftUI, FoveatedStreaming, FoveatedStreamingSimulator, RealityKit, Network; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── FoveatedStreaming-Sample/
    ├── FoveatedStreaming-Sample/
    │   ├── FoveatedStreamingSampleApp.swift
    │   ├── Models/
    │   │   ├── AppModel.swift
    │   │   ├── MessageChannelModel.swift
    │   │   └── StreamActions.swift
    │   ├── Views/
    │   │   ├── StreamConnectionView.swift
    │   │   ├── ContentView.swift
    │   │   ├── MessageChannelView.swift
    │   │   ├── ReopenMainWindowView.swift
    │   │   ├── StreamControlsView.swift
    │   │   └── TransformStreamWidgetView.swift
    │   └── ViewModifiers/
    │       └── SetImmersivePresentationBehaviorsViewModifier.swift
    └── FoveatedStreamingSimulator/
        └── FoveatedStreamingSimulator.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 21 source declaration(s).

Overall architecture

Reference code

FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:12 — architecture anchor

#if targetEnvironment(simulator)
@main
struct FoveatedStreamingSampleApp: App {
    // ...
            Text("FoveatedStreamingSampleApp is unsupported on the simulator. Please use a device to run this sample.")
    // ...
}
#endif

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 Foveated Streaming.

Ownership and state

Ownership evidence

FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:26 — stored dependency or nearest verified ownership anchor

#if targetEnvironment(simulator)
// ...
#else
@main
struct FoveatedStreamingSampleApp: App {
    private let session = FoveatedStreamingSession()
    // ...
}
#endif
Owner Object or state Relationship Mutation authority
FoveatedStreamingSampleApp FoveatedStreamingSession (session) creates and retains Initialized by the owner; the binding is immutable
FoveatedStreamingSampleApp AppModel (appModel) creates and retains Initialized by the owner; the binding is immutable
FoveatedStreamingSampleApp MessageChannelModel (messageChannelModel) stores or receives Initialized by the owner; the binding is immutable
MessageChannelModel FoveatedStreamingSession (session) 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.

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
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:43
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/AppModel.swift:10
Main isolation Task closure isolated to MainActor The cited operation explicitly enters a main-actor-isolated region. FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift:41
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift:41
Transfer contract Sendable or @Sendable The source declares a sendability boundary; this alone does not synchronize mutable state. FoveatedStreaming-Sample/FoveatedStreamingSimulator/FoveatedStreamingSimulator.swift:15

@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

FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:43 — representative execution boundary

#if targetEnvironment(simulator)
// ...
#else
@main
struct FoveatedStreamingSampleApp: App {
    // ...
}
#endif

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. FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/AppModel.swift:11
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. FoveatedStreaming-Sample/FoveatedStreaming-Sample/ViewModifiers/SetImmersivePresentationBehaviorsViewModifier.swift:25
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:8
Source import FoveatedStreaming The cited file imports this module; runtime use and architectural role are not inferred. FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:22
Source import FoveatedStreamingSimulator The cited file imports this module; runtime use and architectural role are not inferred. FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/StreamActions.swift:10
Source import RealityKit The cited file imports this module; runtime use and architectural role are not inferred. FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:9
Source import Network The cited file imports this module; runtime use and architectural role are not inferred. FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/StreamConnectionView.swift:10
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. FoveatedStreaming-Sample/FoveatedStreamingSimulator/FoveatedStreamingSimulator.swift:9

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

FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:13 — representative type boundary

#if targetEnvironment(simulator)
@main
struct FoveatedStreamingSampleApp: App {
    // ...
}
#endif
Type Responsibility Depends on or conforms to
FoveatedStreamingSampleApp Application entry and top-level composition App
FoveatedStreamingSampleApp Application entry and top-level composition App
AppModel Feature data or observable state Concrete collaborators/imported frameworks
MessageChannelModel Feature data or observable state Concrete collaborators/imported frameworks
StreamConnectionView User-interface presentation and input forwarding View
ContentView User-interface presentation and input forwarding View
DeveloperSettingsView User-interface presentation and input forwarding View
ReopenMainWindowView User-interface presentation and input forwarding View
StreamControlsView User-interface presentation and input forwarding View
TransformStreamWidgetView User-interface presentation and input forwarding View

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
session (FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:26) 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.
appModel (FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:27) 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.
messageChannelModel (FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.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.
monitorAvailableChannels (FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift:35) 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

FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:26 — representative boundary

#if targetEnvironment(simulator)
// ...
#else
@main
struct FoveatedStreamingSampleApp: App {
    // ...
}
#endif

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 FoveatedStreamingSampleApp The source’s App suffix makes this role explicit.
Feature data or observable state AppModel, MessageChannelModel The source’s Model suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, DeveloperSettingsView, ReopenMainWindowView, StreamConnectionView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Binding-based state propagation FoveatedStreaming-Sample/FoveatedStreaming-Sample/ViewModifiers/TrackWindowStateViewModifier.swift:18 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: App: FoveatedStreamingSampleApp; Model: AppModel, MessageChannelModel; View: ContentView, DeveloperSettingsView, ReopenMainWindowView, StreamConnectionView, StreamControlsView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: monitorAvailableChannels, setUpMessageChannel, startReceivingMessages, local, remote, sendMessage.
  • Files: FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift, FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/AppModel.swift, FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift, FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/StreamConnectionView.swift, FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ContentView.swift, FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ReopenMainWindowView.swift.

Architecture takeaways

  • FoveatedStreamingSampleApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, FoveatedStreaming, FoveatedStreamingSimulator, RealityKit 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
FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift Cited implementation, FoveatedStreamingSampleApp, await suspension point, SwiftUI, FoveatedStreaming, RealityKit
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift Cited implementation, Task closure isolated to MainActor, Task, MessageChannelModel
FoveatedStreaming-Sample/FoveatedStreaming-Sample/ViewModifiers/TrackWindowStateViewModifier.swift Cited implementation, TrackWindowStateViewModifier
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/AppModel.swift @MainActor, @Observable, AppModel, WindowState
FoveatedStreaming-Sample/FoveatedStreamingSimulator/FoveatedStreamingSimulator.swift Sendable or @Sendable, Foundation, Status, DisconnectReason, Value, Endpoint
FoveatedStreaming-Sample/FoveatedStreaming-Sample/ViewModifiers/SetImmersivePresentationBehaviorsViewModifier.swift SwiftUI state property wrapper, SetImmersivePresentationBehaviorsViewModifier
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/StreamActions.swift FoveatedStreamingSimulator, StreamActions
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/StreamConnectionView.swift Network, ConnectionMode, StreamConnectionView
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ContentView.swift ContentView
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/MessageChannelView.swift DeveloperSettingsView
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ReopenMainWindowView.swift ReopenMainWindowView
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/StreamControlsView.swift StreamControlsView
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/TransformStreamWidgetView.swift TransformStreamWidgetView
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ConnectionActionButton.swift ConnectionActionButton