Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Designing no-code games with Reality Composer Pro 3

At a glance

Item Summary
Purpose Build a video game in Reality Composer Pro without code using Script Graphs.
App architecture A Shell, Swift sample with the source-visible chain SquirrelAppContentViewSwiftUI / RealityKit APIs.
Main patterns Binding-based state propagation
Project style 9 scanned source file(s) across Shell, Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: await suspension point, DispatchQueue.main.async, @MainActor, Task closure isolated to MainActor, Task; none alone proves a background thread.
State/event model Source-visible mechanisms: SwiftUI state property wrapper, AnyCancellable.
Key frameworks/packages SwiftUI, os, RealityKit, RealityKitScripting, Combine; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── Squirrel/
│   ├── SquirrelApp.swift
│   ├── DinnerBubbleView.swift
│   ├── ContentView.swift
│   ├── SquirrelTalkAttachmentView.swift
│   ├── ContentViewAttachments.swift
│   └── UIPreview.swift
├── Configuration/
│   ├── EmbedFrameworks.sh
│   ├── ExportRealityFiles.sh
│   ├── InstallPlugin.sh
│   ├── AppConfig.xcconfig
│   └── SampleCode.xcconfig
└── Squirrel.xcodeproj/
    └── .xcodesamplecode.plist

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: Shell, Swift.
  • The verified tree contains 5 project/configuration file(s) and 8 source declaration(s).

Overall architecture

Reference code

Squirrel/SquirrelApp.swift:18 — architecture anchor

@main
struct SquirrelApp: App {

    init() {
        do {
            // Initialize the Script Graph runtime before any RealityView loads
            // a scene that contains `ScriptingComponent`s. `.subtracting(.ar)`
            // disables AR input because this sample runs in a volumetric window.
            try RKS.initialize(inputOptions: .all.subtracting(.ar))
        } catch {
            assertionFailure("Failed to initialize the Script Graph runtime: \(error)")
        }
    }

    var body: some SwiftUI.Scene {
        WindowGroup {
            ContentView()
        }
        #if os(visionOS)
            .windowStyle(.volumetric)
            .defaultSize(width: 1.8, height: 1.8, depth: 1.2, in: .meters)
        #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 visionOS.

Ownership and state

Ownership evidence

Squirrel/SquirrelApp.swift:15 — stored dependency or nearest verified ownership anchor

let logger = Logger(subsystem: "com.example.apple-samplecode.Squirrel", category: "Squirrel")
Owner Object or state Relationship Mutation authority
SquirrelApp Logger (logger) creates and retains Initialized by the owner; the binding is immutable
TreeTalkAttachmentView Bool (isVisible) owns value state Initialized by the owner; the binding is immutable
TreeTalkAttachmentView String (text) owns value state Initialized by the owner; the binding is immutable
SpeechBubbleShape CGFloat (insetAmount) 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
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. Squirrel/ContentView.swift:42
Queue scheduling DispatchQueue.main.async The source addresses the main dispatch queue. Squirrel/ContentView.swift:112
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. Squirrel/ContentView.swift:196
Main isolation Task closure isolated to MainActor The cited operation explicitly enters a main-actor-isolated region. Squirrel/ContentView.swift:196
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. Squirrel/ContentView.swift:196

@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

Squirrel/ContentView.swift:42 — representative execution boundary

struct ContentView: View {
    // ...
                let entity = (try await Entity(named: "world"))
    // ...
}

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 SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. Squirrel/ContentView.swift:15
State propagation AnyCancellable A cancellable value records subscription lifetime management. Squirrel/ContentView.swift:17
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. Squirrel/ContentView.swift:10
Source import os The cited file imports this module; runtime use and architectural role are not inferred. Squirrel/ContentView.swift:12
Source import RealityKit The cited file imports this module; runtime use and architectural role are not inferred. Squirrel/ContentView.swift:8
Source import RealityKitScripting The cited file imports this module; runtime use and architectural role are not inferred. Squirrel/ContentView.swift:9
Source import Combine The cited file imports this module; runtime use and architectural role are not inferred. Squirrel/ContentView.swift:11

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

Squirrel/SquirrelApp.swift:19 — representative type boundary

@main
struct SquirrelApp: App {
    // ...
            try RKS.initialize(inputOptions: .all.subtracting(.ar))
    // ...
}
Type Responsibility Depends on or conforms to
SquirrelApp Application entry and top-level composition App
TreeTalkAttachmentView User-interface presentation and input forwarding View
ContentView User-interface presentation and input forwarding View
SquirrelTalkAttachmentView User-interface presentation and input forwarding View
SpeechBubbleShape Represents a feature value or composable behavior InsettableShape
StartButtonAttachment Represents a feature value or composable behavior View
EndScreenAttachment Represents a feature value or composable behavior View
OrnamentBar Represents a feature value or composable behavior 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
sendSceneEvent (Squirrel/ContentView.swift:291) 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.
jumpToScene (Squirrel/ContentView.swift:301) 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.
formatPlayTime (Squirrel/ContentView.swift:309) 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.
levelSwitches (Squirrel/ContentViewAttachments.swift:78) 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

Squirrel/ContentView.swift:291 — representative boundary

    private func sendSceneEvent(eventName: String) {
        guard let scene = self.scene?.scene else {
            return
        }
        scene.send(name: eventName)
    }

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 SquirrelApp The source’s App suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, SquirrelTalkAttachmentView, TreeTalkAttachmentView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Binding-based state propagation Squirrel/ContentViewAttachments.swift:11 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: App: SquirrelApp; View: ContentView, SquirrelTalkAttachmentView, TreeTalkAttachmentView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: inset, path, addCorner, sendSceneEvent, jumpToScene, formatPlayTime, scriptingEntity.
  • Files: Squirrel/SquirrelApp.swift, Squirrel/ContentView.swift, Squirrel/SquirrelTalkAttachmentView.swift.

Architecture takeaways

  • SquirrelApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, RealityKit, RealityKitScripting 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
Squirrel/SquirrelApp.swift Cited implementation, SquirrelApp
Squirrel/ContentView.swift Cited implementation, await suspension point, DispatchQueue.main.async, @MainActor, Task closure isolated to MainActor, Task, SwiftUI state property wrapper, AnyCancellable, SwiftUI, os, RealityKit, RealityKitScripting, Combine, ContentView
Squirrel/ContentViewAttachments.swift Cited implementation, StartButtonAttachment, EndScreenAttachment, OrnamentBar
Squirrel/DinnerBubbleView.swift TreeTalkAttachmentView, SpeechBubbleShape
Squirrel/SquirrelTalkAttachmentView.swift SquirrelTalkAttachmentView
Configuration/EmbedFrameworks.sh Feature implementation
Configuration/ExportRealityFiles.sh Feature implementation
Configuration/InstallPlugin.sh Feature implementation
Squirrel/UIPreview.swift Feature implementation