Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Implementing adjustable material

At a glance

Item Summary
Purpose Update the adjustable parameters of a 3D model in visionOS.
App architecture GlassApp composes WindowGroup around MainView; view-local SwiftUI state owns interaction while RealityView manages the entity graph.
Main patterns SwiftUI scene composition, SwiftUI–RealityKit bridge
Project style Code-light sample with 4 scanned Swift file(s) and 147 Swift line(s); resources and generated assets are excluded from those counts.

Project structure

Source bundle/
└── Glass/
    ├── App/
    │   └── EntryPoint.swift  # GlassApp
    ├── Views/
    │   ├── GlassView.swift  # GlassView
    │   └── MainView.swift  # MainView
    └── Extentions/
        └── Entity.swift

Structure observations

  • The runtime boundary is WindowGroup; the pruned tree lists only files that explain lifecycle, state, or framework integration.
  • App code is compact; any explicit model, provider, or entity owner is still shown below rather than collapsed into view-local state.

Overall architecture

Reference code

Glass/App/EntryPoint.swift:11 — the app or executable entry declares the outer scene lifecycle.

struct GlassApp: App {
    var body: some Scene {
        WindowGroup {
            MainView()
        }
    }
}

The diagram is a responsibility flow, not a claim that every adjacent node directly calls the next. It keeps scene ownership, shared state, RealityKit content, and framework-provider work at separate levels.

Ownership and state

Ownership evidence

Glass/Views/GlassView.swift:20 — representative stored state or the nearest verified lifecycle anchor.

struct GlassView: View {
    // ...
    @State var entity: Entity?
    // ...
}
Owner Object or state Relationship Mutation authority
GlassView Entity as entity owns a SwiftUI-managed reference slot The owning type coordinates writes

Ownership here is deliberately narrow: @Environment and weak references are shared links, initialized @State or stored services are lifecycle ownership, and a RealityView content closure owns additions to its entity graph without making the SwiftUI view a reference-type owner.

Class and protocol design

Type Responsibility Depends on or conforms to
GlassApp (Glass/App/EntryPoint.swift:11) Declares app scenes and top-level dependency lifetime. App
MainView (Glass/Views/MainView.swift:10) Presents UI and forwards gestures or lifecycle events. View
GlassView (Glass/Views/GlassView.swift:12) Presents UI and forwards gestures or lifecycle events. View

The source defines no local substitution protocol in the reviewed boundary. Its protocol use is framework-facing (App, View, RealityKit/ARKit protocols, or platform adapters), so this document does not label the whole app protocol-oriented.

Access control

Symbol Access Verified effect Likely rationale
public func updateMaterials(_ update: (inout Material) -> Void) { (Glass/Extentions/Entity.swift:13) public The declaration is available to importing modules, subject to its containing type’s visibility. Inference: Satisfy a cross-target or framework-facing surface without implying subclassability.

No reviewed declaration uses fileprivate, private(set), open; unmodified Swift declarations are internal.

Reference code

Glass/Extentions/Entity.swift:13 — representative visibility boundary.

    public func updateMaterials(_ update: (inout Material) -> Void) {
        // ...
    }

Logic ownership and placement

Logic Owning type or file Placement rationale
Scene declaration and dependency lifetime GlassApp The App/entry boundary determines window, volume, and immersive-space lifetime.
Presentation, attachments, and gestures MainView SwiftUI view code forwards user intent and RealityView lifecycle events.

Design patterns

Pattern Source evidence Purpose or tradeoff
SwiftUI scene composition Glass/App/EntryPoint.swift:11 Keeps windows, volumes, and immersive-space lifecycle visible at the app boundary.
SwiftUI–RealityKit bridge Glass/Views/GlassView.swift:24 Builds and updates a RealityKit entity graph from SwiftUI lifecycle closures.

Naming conventions

  • Role suffixes are evidence, not decoration: App: GlassApp; View: GlassView, MainView.
  • Protocols: no app-defined protocol in the reviewed source.
  • Commands use verb-led methods: updateMaterials.
  • Files generally match their primary type; Views, Models, Managers, Providers, Components, Systems, and Packages folders describe architectural roles where present.

Architecture takeaways

  • Treat GlassApp as the owner of scene declarations, not as the owner of every RealityKit entity created later.
  • Keep view-local interaction in SwiftUI, but move provider sessions, playback resources, shared game state, or transport state into a stable owner when their lifetime exceeds one render pass.
  • The compact source does not justify adding repository, coordinator, or protocol layers beyond the model, provider, or view boundary the sample actually declares.

Source map

Source file Relevant symbols
Glass/App/EntryPoint.swift:11 GlassApp
Glass/Views/GlassView.swift:12 GlassView
Glass/Views/MainView.swift:10 MainView
Glass/Extentions/Entity.swift:1 Feature implementation