Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Diorama

At a glance

Item Summary
Purpose Design scenes for your visionOS app using Reality Composer Pro.
App architecture A Swift sample with the source-visible chain DioramaAppContentViewViewModelAttachmentsProviderRealityKit / SwiftUI APIs.
Main patterns Model-View-ViewModel, Delegate or data-source callbacks
Project style 19 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: Task, await suspension point, @MainActor; none alone proves a background thread.
State/event model Source-visible mechanisms: @Observable, SwiftUI state property wrapper.
Key frameworks/packages RealityKit, SwiftUI, RealityKitContent, Foundation, ARKit; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── Diorama/
│   ├── DioramaApp.swift
│   ├── ViewModel.swift
│   ├── LearnMoreView.swift
│   ├── AttachmentsProvider.swift
│   └── ContentView.swift
└── Packages/
    └── RealityKitContent/
        └── Sources/
            └── RealityKitContent/
                ├── PointOfInterestComponent.swift
                ├── BillboardComponent.swift
                ├── BillboardSystem.swift
                ├── RegionSpecificComponent.swift
                ├── TrailAnimationSystem.swift
                ├── TrailComponent.swift
                └── Style.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 22 source declaration(s).

Overall architecture

Reference code

Diorama/DioramaApp.swift:13 — architecture anchor

@main
struct DioramaApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    // ...
}

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

Diorama/DioramaApp.swift:18 — stored dependency or nearest verified ownership anchor

@main
struct DioramaApp: App {
    // ...
    @State private var viewModel = ViewModel()
    // ...
}
Owner Object or state Relationship Mutation authority
DioramaApp ViewModel (viewModel) owns wrapper-managed state Owning lexical scope
ViewModel Entity (rootEntity) stores or receives App/module collaborators
ViewModel Bool (showImmersiveContent) owns value state App/module collaborators
ViewModel Float (sliderValue) owns value state 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
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. Diorama/ContentView.swift:32
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. Diorama/ContentView.swift:35
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. Diorama/ViewModel.swift:77

@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

Diorama/ContentView.swift:32 — representative execution boundary

                    Task {
                        // ...
                            viewModel.resetAudio()
                        // ...
                    }

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. Diorama/AttachmentsProvider.swift:11
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. Diorama/ContentView.swift:15
Source import RealityKit The cited file imports this module; runtime use and architectural role are not inferred. Diorama/Components.swift:8
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. Diorama/AttachmentsProvider.swift:8
Source import RealityKitContent The cited file imports this module; runtime use and architectural role are not inferred. Diorama/Components.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Diorama/FlockingSystem.swift:8
Source import ARKit The cited file imports this module; runtime use and architectural role are not inferred. Diorama/DioramaApp.swift:10
Source import Observation The cited file imports this module; runtime use and architectural role are not inferred. Diorama/AttachmentsProvider.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

Diorama/DioramaApp.swift:14 — representative type boundary

@main
struct DioramaApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    // ...
}
Type Responsibility Depends on or conforms to
DioramaApp Application entry and top-level composition App
AppDelegate Receives callback-driven events NSObject, UIApplicationDelegate
ViewModel UI-facing state and feature coordination Concrete collaborators/imported frameworks
PointOfInterestComponent Stores entity-component data or behavior Component, Codable
BillboardComponent Stores entity-component data or behavior Component, Codable
BillboardSystem Runs entity-component-system update logic System
RegionSpecificComponent Stores entity-component data or behavior Component, Codable
TrailAnimationSystem Runs entity-component-system update logic System
TrailComponent Stores entity-component data or behavior Component, Codable
LearnMoreView 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
update (Diorama/ContentView.swift:78) 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.
immersiveSpaceIdentifier (Diorama/DioramaApp.swift:16) 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.
viewModel (Diorama/DioramaApp.swift:18) 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.
dismiss (Diorama/DioramaView.swift:13) 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.

Reference code

Diorama/ContentView.swift:78 — representative boundary

    private func update() {
        viewModel.updateTerrainMaterial()
        viewModel.updateRegionSpecificOpacity()
    }

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 DioramaApp The source’s App suffix makes this role explicit.
Stores entity-component data or behavior BillboardComponent, ControlledOpacityComponent, FlockingComponent, PointOfInterestComponent The source’s Component suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.
Supplies a capability or framework resource AttachmentsProvider The source’s Provider suffix makes this role explicit.
Runs entity-component-system update logic BillboardSystem, FlockingSystem, TrailAnimationSystem The source’s System suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, DioramaView, ImagesView, LearnMoreView The source’s View suffix makes this role explicit.
UI-facing state and feature coordination ViewModel The source’s ViewModel suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Model-View-ViewModel Diorama/ViewModel.swift:14 Role-named view models keep UI-facing state or coordination outside view declarations.
Delegate or data-source callbacks Diorama/DioramaApp.swift:50 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: App: DioramaApp; Component: BillboardComponent, ControlledOpacityComponent, FlockingComponent, PointOfInterestComponent, PointOfInterestRuntimeComponent; Delegate: AppDelegate; Provider: AttachmentsProvider; System: BillboardSystem, FlockingSystem, TrailAnimationSystem; View: ContentView, DioramaView, ImagesView, LearnMoreView; ViewModel: ViewModel.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: applicationShouldTerminateAfterLastWindowClosed, updateScale, updateRegionSpecificOpacity, setupAudio, resetAudio, updateTerrainMaterial, opacity, gain.
  • Files: Diorama/DioramaApp.swift, Diorama/ViewModel.swift, Packages/RealityKitContent/Sources/RealityKitContent/PointOfInterestComponent.swift, Packages/RealityKitContent/Sources/RealityKitContent/BillboardComponent.swift, Packages/RealityKitContent/Sources/RealityKitContent/BillboardSystem.swift, Packages/RealityKitContent/Sources/RealityKitContent/RegionSpecificComponent.swift.

Architecture takeaways

  • DioramaApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches RealityKit, SwiftUI, RealityKitContent, ARKit 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
Diorama/DioramaApp.swift Cited implementation, DioramaApp, ARKit, AppDelegate
Diorama/ContentView.swift Cited implementation, Task, await suspension point, SwiftUI state property wrapper, ContentView
Diorama/DioramaView.swift Cited implementation, DioramaView
Diorama/ViewModel.swift ViewModel, @MainActor
Diorama/AttachmentsProvider.swift @Observable, SwiftUI, Observation, AttachmentsProvider
Diorama/Components.swift RealityKit, RealityKitContent, PointOfInterestRuntimeComponent, ControlledOpacityComponent
Diorama/FlockingSystem.swift Foundation, FlockingSystem
Packages/RealityKitContent/Sources/RealityKitContent/PointOfInterestComponent.swift Region, PointOfInterestComponent
Packages/RealityKitContent/Sources/RealityKitContent/BillboardComponent.swift BillboardComponent
Packages/RealityKitContent/Sources/RealityKitContent/BillboardSystem.swift BillboardSystem
Packages/RealityKitContent/Sources/RealityKitContent/RegionSpecificComponent.swift RegionSpecificComponent
Packages/RealityKitContent/Sources/RealityKitContent/TrailAnimationSystem.swift TrailAnimationSystem
Packages/RealityKitContent/Sources/RealityKitContent/TrailComponent.swift TrailComponent
Diorama/LearnMoreView.swift LearnMoreView, ImagesView
Packages/RealityKitContent/Sources/RealityKitContent/Style.swift GreenBackground, TitleStyle, DioramaSliderStyle
Diorama/FlockingComponent.swift FlockingComponent