Combining 2D and 3D views in an immersive app
At a glance
| Item | Summary |
|---|---|
| Purpose | Use attachments to place 2D content relative to 3D content in your visionOS app. |
| App architecture | A Swift sample with the source-visible chain MultiDimensionalImmersiveContentApp → RainbowView → RainbowModel → RealityKit APIs. |
| Main patterns | No named application pattern supported by the extracted structure |
| Project style | 11 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, await suspension point; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, UIKit, RealityKit, Foundation, PackageDescription; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── MultiDimensionalImmersiveContent/
│ ├── MultiDimensionalImmersiveContentApp.swift
│ ├── RainbowModel.swift
│ ├── SwiftUIArch/
│ │ └── SwiftUIArcView.swift
│ ├── CALayerArch/
│ │ ├── CALayerArcView.swift
│ │ └── CALayerArcRepresentable.swift
│ ├── RainbowView.swift
│ ├── UIViewArch/
│ │ ├── UIViewArcView.swift
│ │ └── UIViewArcRepresentable.swift
│ └── Extensions.swift
├── Packages/
│ └── RealityKitContent/
│ ├── Sources/
│ │ └── RealityKitContent/
│ │ └── RealityKitContent.swift
│ └── Package.swift
└── Configuration/
└── SampleCode.xcconfig
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 13 source declaration(s).
Overall architecture
flowchart LR
N1["MultiDimensionalImmersiveContentApp"]
N2["RainbowView"]
N3["RainbowModel"]
N4["RealityKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
MultiDimensionalImmersiveContent/MultiDimensionalImmersiveContentApp.swift:10 — architecture anchor
@main
struct MultiDimensionalImmersiveContentApp: App {
var body: some Scene {
ImmersiveSpace(id: "ImmersiveSpace") {
RainbowView()
}
}
}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
RainbowModel *-- Array : archAttachments
RainbowModel *-- Array : tapAttachments
RainbowModel *-- EntityData : plane
RainbowModel *-- Array : realityKitAssets
Ownership evidence
MultiDimensionalImmersiveContent/RainbowModel.swift:17 — stored dependency or nearest verified ownership anchor
@Observable
class RainbowModel {
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
RainbowModel |
Array (archAttachments) |
owns value state | App/module collaborators |
RainbowModel |
Array (tapAttachments) |
owns value state | App/module collaborators |
RainbowModel |
EntityData (plane) |
creates and retains | App/module collaborators |
RainbowModel |
Array (realityKitAssets) |
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 |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | MultiDimensionalImmersiveContent/RainbowView.swift:12 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | MultiDimensionalImmersiveContent/RainbowView.swift:25 |
@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
MultiDimensionalImmersiveContent/RainbowView.swift:12 — representative execution boundary
@MainActor struct RainbowView: View {
// ...
@State private var rainbowModel = RainbowModel()
// ...
}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. | MultiDimensionalImmersiveContent/RainbowModel.swift:13 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | MultiDimensionalImmersiveContent/RainbowView.swift:14 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiDimensionalImmersiveContent/CALayerArch/CALayerArcRepresentable.swift:9 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiDimensionalImmersiveContent/CALayerArch/CALayerArcRepresentable.swift:8 |
| Source import | RealityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiDimensionalImmersiveContent/Extensions.swift:9 |
| 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 |
| Source import | RealityKitContent |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiDimensionalImmersiveContent/RainbowView.swift:10 |
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
MultiDimensionalImmersiveContent/MultiDimensionalImmersiveContentApp.swift:11 — representative type boundary
@main
struct MultiDimensionalImmersiveContentApp: App {
// ...
RainbowView()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
MultiDimensionalImmersiveContentApp |
Application entry and top-level composition | App |
RainbowModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
SwiftUIArcView |
User-interface presentation and input forwarding | View |
CALayerArcView |
User-interface presentation and input forwarding | UIView |
RainbowView |
User-interface presentation and input forwarding | View |
UIViewArcView |
User-interface presentation and input forwarding | UIView |
EntityData |
Represents feature data | Identifiable |
ArchAttachmentColor |
Defines a closed set of feature states or choices | String |
ArchAttachment |
Represents a feature value or composable behavior | Identifiable |
CloudTapAttachment |
Represents a feature value or composable behavior | Identifiable |
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 |
|---|---|---|---|
layoutSubviews (MultiDimensionalImmersiveContent/CALayerArch/CALayerArcView.swift:31) |
open |
The class/member is visible and supports external subclassing or overriding. | Inference: intentionally permit external subclassing or overriding. |
rainbowModel (MultiDimensionalImmersiveContent/RainbowView.swift:14) |
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. |
root (MultiDimensionalImmersiveContent/RainbowView.swift:17) |
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. |
physicalMetrics (MultiDimensionalImmersiveContent/RainbowView.swift:19) |
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
MultiDimensionalImmersiveContent/CALayerArch/CALayerArcView.swift:31 — representative boundary
open override func layoutSubviews() {
super.layoutSubviews()
// ...
}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 | MultiDimensionalImmersiveContentApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | RainbowModel |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | CALayerArcView, RainbowView, SwiftUIArcView, UIViewArcView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| No named application pattern | MultiDimensionalImmersiveContent/MultiDimensionalImmersiveContentApp.swift:10 |
The verified source directly composes concrete framework types; this document avoids forcing a pattern name. |
Naming conventions
- Types: App: MultiDimensionalImmersiveContentApp; Model: RainbowModel; View: CALayerArcView, RainbowView, SwiftUIArcView, UIViewArcView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
path,didMoveToSuperview,layoutSubviews,addAttachments,createArchAttachment,createAndPositionTapEntity,scaleAndPositionArches,createEntity. - Files:
MultiDimensionalImmersiveContent/MultiDimensionalImmersiveContentApp.swift,MultiDimensionalImmersiveContent/RainbowModel.swift,MultiDimensionalImmersiveContent/SwiftUIArch/SwiftUIArcView.swift,MultiDimensionalImmersiveContent/CALayerArch/CALayerArcView.swift,MultiDimensionalImmersiveContent/RainbowView.swift,MultiDimensionalImmersiveContent/UIViewArch/UIViewArcView.swift.
Architecture takeaways
MultiDimensionalImmersiveContentAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, UIKit, RealityKit, 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 |
|---|---|
MultiDimensionalImmersiveContent/MultiDimensionalImmersiveContentApp.swift |
Cited implementation, MultiDimensionalImmersiveContentApp |
MultiDimensionalImmersiveContent/RainbowModel.swift |
Cited implementation, @Observable, RainbowModel, EntityData, ArchAttachmentColor, ArchAttachment, CloudTapAttachment |
MultiDimensionalImmersiveContent/CALayerArch/CALayerArcView.swift |
Cited implementation, CALayerArcView |
MultiDimensionalImmersiveContent/RainbowView.swift |
Cited implementation, @MainActor, await suspension point, SwiftUI state property wrapper, RealityKitContent, RainbowView |
MultiDimensionalImmersiveContent/CALayerArch/CALayerArcRepresentable.swift |
SwiftUI, UIKit, CALayerArcViewRep |
MultiDimensionalImmersiveContent/Extensions.swift |
RealityKit, Feature implementation |
Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift |
Foundation, Feature implementation |
Packages/RealityKitContent/Package.swift |
PackageDescription, Feature implementation |
MultiDimensionalImmersiveContent/SwiftUIArch/SwiftUIArcView.swift |
SwiftUIArcView, Arc |
MultiDimensionalImmersiveContent/UIViewArch/UIViewArcView.swift |
UIViewArcView |
MultiDimensionalImmersiveContent/UIViewArch/UIViewArcRepresentable.swift |
UIViewArcViewRep |