Construct an immersive environment for visionOS
At a glance
| Item | Summary |
|---|---|
| Purpose | Build efficient custom worlds for your app. |
| App architecture | A Swift sample with the source-visible chain MeadowApp → ContentView → EnvironmentLoader → RealityKit / RealityKitContent APIs. |
| Main patterns | Actor isolation |
| Project style | 6 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: await suspension point, Task, actor; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper. |
| Key frameworks/packages | RealityKit, RealityKitContent, SwiftUI, Foundation, PackageDescription; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── Meadow/
│ ├── MeadowApp.swift
│ ├── ContentView.swift
│ ├── EnvironmentLoader.swift
│ ├── ImmersiveView.swift
│ └── Info.plist
├── Packages/
│ └── RealityKitContent/
│ ├── Sources/
│ │ └── RealityKitContent/
│ │ └── RealityKitContent.swift
│ └── Package.swift
├── Configuration/
│ └── SampleCode.xcconfig
└── Custom Meadow Immersive Environment.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 4 source declaration(s).
Overall architecture
flowchart LR
N1["MeadowApp"]
N2["ContentView"]
N3["EnvironmentLoader"]
N4["RealityKit / RealityKitContent APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Meadow/MeadowApp.swift:10 — architecture anchor
@main
struct MeadowApp: App {
@State var loader = EnvironmentLoader()
var body: some Scene {
// Window with a portal to the environment
WindowGroup(id: "Window") {
ContentView(loader: loader)
}.windowStyle(.plain)
// ImmersiveSpace showing the environment
ImmersiveSpace(id: "ImmersiveSpace") {
ImmersiveView(loader: loader)
}.immersionStyle(selection: .constant(.progressive), in: .progressive)
}
}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 RealityKit.
Ownership and state
classDiagram
MeadowApp *-- EnvironmentLoader : loader
ContentView o-- EnvironmentLoader : loader
ContentView *-- Entity : root
ContentView *-- ModelEntity : portalPlane
Ownership evidence
Meadow/MeadowApp.swift:13 — stored dependency or nearest verified ownership anchor
@main
struct MeadowApp: App {
// ...
@State var loader = EnvironmentLoader()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
MeadowApp |
EnvironmentLoader (loader) |
owns wrapper-managed state | App/module collaborators |
ContentView |
EnvironmentLoader (loader) |
stores or receives | App/module collaborators |
ContentView |
Entity (root) |
creates and retains | Initialized by the owner; the binding is immutable |
ContentView |
ModelEntity (portalPlane) |
creates and retains | 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. | Meadow/ContentView.swift:33 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | Meadow/ContentView.swift:54 |
| Actor isolation | actor |
The cited type is actor-isolated; this does not select a background thread. | Meadow/EnvironmentLoader.swift:13 |
@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
Meadow/ContentView.swift:33 — representative execution boundary
struct ContentView: View {
// ...
world.addChild(try! await loader.getEntity())
// ...
}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. | Meadow/ContentView.swift:23 |
| Source import | RealityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Meadow/ContentView.swift:9 |
| Source import | RealityKitContent |
The cited file imports this module; runtime use and architectural role are not inferred. | Meadow/ContentView.swift:10 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | Meadow/ContentView.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:8 |
| Source import | PackageDescription |
The cited file imports this module; runtime use and architectural role are not inferred. | Packages/RealityKitContent/Package.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
Meadow/MeadowApp.swift:11 — representative type boundary
@main
struct MeadowApp: App {
// ...
@State var loader = EnvironmentLoader()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
MeadowApp |
Application entry and top-level composition | App |
ContentView |
User-interface presentation and input forwarding | View |
EnvironmentLoader |
Loads and prepares feature data or resources | Concrete collaborators/imported frameworks |
ImmersiveView |
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 |
|---|---|---|---|
entity (Meadow/EnvironmentLoader.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. |
realityKitContentBundle (Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:11) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
ContentView (Meadow/ContentView.swift:8) |
implicit internal |
No explicit modifier means the Swift declaration is internal to the module. | Inference: app-target collaboration needs no exported library surface. |
Reference code
Meadow/EnvironmentLoader.swift:16 — representative boundary
actor EnvironmentLoader {
// ...
private weak var entity: Entity?
// ...
}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 | MeadowApp |
The source’s App suffix makes this role explicit. |
| Loads and prepares feature data or resources | EnvironmentLoader |
The source’s Loader suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, ImmersiveView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Actor isolation | Meadow/EnvironmentLoader.swift:13 |
A declared actor creates an explicit isolation boundary; its executor is not described as a background thread. |
Naming conventions
- Types: App: MeadowApp; Loader: EnvironmentLoader; View: ContentView, ImmersiveView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
getEntity. - Files:
Meadow/MeadowApp.swift,Meadow/ContentView.swift,Meadow/EnvironmentLoader.swift,Meadow/ImmersiveView.swift.
Architecture takeaways
MeadowAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches RealityKit, RealityKitContent, SwiftUI, PackageDescription 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 |
|---|---|
Meadow/MeadowApp.swift |
Cited implementation, MeadowApp |
Meadow/EnvironmentLoader.swift |
Cited implementation, EnvironmentLoader, actor |
Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift |
Cited implementation, Foundation, Feature implementation |
Meadow/ContentView.swift |
ContentView, await suspension point, Task, SwiftUI state property wrapper, RealityKit, RealityKitContent, SwiftUI |
Packages/RealityKitContent/Package.swift |
PackageDescription, Feature implementation |
Meadow/ImmersiveView.swift |
ImmersiveView |