Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Manipulating entities with solid collisions

At a glance

Item Summary
Purpose Extend the capabilities of your app by using entities, components, and systems to maintain solid collisions when manipulating entities.
App architecture ManipulateWithSolidCollisionsApp composes WindowGroup + volumetric window around ContentView; AppModel holds shared experience state and RealityKit components and systems own per-entity behavior.
Main patterns SwiftUI scene composition, SwiftUI–RealityKit bridge, Observable state owner, Entity-component-system
Project style Code-rich sample with 11 scanned Swift file(s) and 560 Swift line(s); resources and generated assets are excluded from those counts.

Project structure

Source bundle/
├── ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift  # ManipulateWithSolidCollisionsApp
├── ManipulateWithSolidCollisions/AppModel.swift  # AppModel
├── ManipulateWithSolidCollisions/ContentView.swift  # ContentView
├── ManipulateWithSolidCollisions/DemoView.swift  # DemoView
├── ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsComponent.swift  # ManipulateWithSolidCollisionsComponent
├── ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsSystem.swift  # ManipulateWithSolidCollisionsSystem
├── ManipulateWithSolidCollisions/ECS/ResetTransformComponent.swift  # ResetTransformComponent
├── ManipulateWithSolidCollisions/ECS/ResetTransformSystem.swift  # ResetTransformSystem
└── Packages/RealityKitContent/Package.realitycomposerpro/ProjectData/main.json  # authored RealityKit content

Structure observations

  • The runtime boundary is WindowGroup + volumetric window; the pruned tree lists only files that explain lifecycle, state, or framework integration.
  • App code is split into role-named views, models, managers, providers, components, or systems.
  • Authored .reality or Reality Composer Pro content is a real implementation boundary; Swift loads or drives it rather than reproducing its entity graph.

Overall architecture

Reference code

ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift:12 — the app or executable entry declares the outer scene lifecycle.

struct ManipulateWithSolidCollisionsApp: App {
    // ...
}

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

ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift:14 — representative stored state or the nearest verified lifecycle anchor.

@main
struct ManipulateWithSolidCollisionsApp: App {
    // ...
    @State private var appModel = AppModel()
    // ...
}
Owner Object or state Relationship Mutation authority
ManipulateWithSolidCollisionsApp AppModel as appModel creates and retains Only the declaring scope writes
ContentView AppModel as appModel receives a shared/non-owning reference The upstream owner controls lifetime; this scope may invoke its mutable API
ManipulateWithSolidCollisionsComponent Entity as proxy receives a shared/non-owning reference The upstream owner controls lifetime; this scope may invoke its mutable API
ManipulateWithSolidCollisionsComponent CollisionGroup as originalCollisionGroup stores and coordinates 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
ManipulateWithSolidCollisionsApp (ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift:12) Declares app scenes and top-level dependency lifetime. App
ContentView (ManipulateWithSolidCollisions/ContentView.swift:12) Presents UI and forwards gestures or lifecycle events. View
AppModel (ManipulateWithSolidCollisions/AppModel.swift:13) Owns observable feature state and domain transitions. Concrete framework collaborators
ManipulateWithSolidCollisionsComponent (ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsComponent.swift:12) Stores RealityKit entity data. Component
ManipulateWithSolidCollisionsSystem (ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsSystem.swift:11) Updates matching RealityKit entities. System
ResetTransformComponent (ManipulateWithSolidCollisions/ECS/ResetTransformComponent.swift:10) Stores RealityKit entity data. Component
ResetTransformSystem (ManipulateWithSolidCollisions/ECS/ResetTransformSystem.swift:12) Updates matching RealityKit entities. System

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
@State private var appModel = AppModel() (ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift:14) private Use is restricted to the declaration and same-file extensions permitted by Swift. Inference: Hide implementation details and lifecycle-sensitive state.
public let realityKitContentBundle = Bundle.module (Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:10) public The declaration is available to importing modules, subject to its containing type’s visibility. Inference: Export the type across the package-module boundary.

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

Reference code

ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift:14 — representative visibility boundary.

@main
struct ManipulateWithSolidCollisionsApp: App {
    // ...
    @State private var appModel = AppModel()
    // ...
}

Logic ownership and placement

Logic Owning type or file Placement rationale
Scene declaration and dependency lifetime ManipulateWithSolidCollisionsApp The App/entry boundary determines window, volume, and immersive-space lifetime.
Presentation, attachments, and gestures ContentView SwiftUI view code forwards user intent and RealityView lifecycle events.
Shared feature state and commands AppModel A role-named owner prevents sibling views from duplicating transitions.
Per-frame entity behavior ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsSystem.swift:11 RealityKit systems query component data instead of centralizing every entity update in SwiftUI.

Design patterns

Pattern Source evidence Purpose or tradeoff
SwiftUI scene composition ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift:12 Keeps windows, volumes, and immersive-space lifecycle visible at the app boundary.
SwiftUI–RealityKit bridge ManipulateWithSolidCollisions/DemoView.swift:14 Builds and updates a RealityKit entity graph from SwiftUI lifecycle closures.
Observable state owner ManipulateWithSolidCollisions/AppModel.swift:13 Shares feature state across multiple views without moving framework resources into view values.
Entity-component-system ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsSystem.swift:11 Stores per-entity data in components and advances behavior in registered RealityKit systems.

Naming conventions

  • Role suffixes are evidence, not decoration: App: ManipulateWithSolidCollisionsApp; Model: AppModel; View: ContentView, DemoView.
  • ECS names pair data and behavior: components ManipulateWithSolidCollisionsComponent, ResetTransformComponent; systems ManipulateWithSolidCollisionsSystem, ResetTransformSystem.
  • Protocols: no app-defined protocol in the reviewed source.
  • Commands use verb-led methods: buildSceneEntities, loadAndConfigureProp, configureEntity.
  • Files generally match their primary type; Views, Models, Managers, Providers, Components, Systems, and Packages folders describe architectural roles where present.

Architecture takeaways

  • Treat ManipulateWithSolidCollisionsApp 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.
  • Use RealityKit components for per-entity data and systems for repeated simulation instead of a monolithic view model.

Source map

Source file Relevant symbols
ManipulateWithSolidCollisions/ManipulateWithSolidCollisionsApp.swift:12 ManipulateWithSolidCollisionsApp
ManipulateWithSolidCollisions/AppModel.swift:13 AppModel
ManipulateWithSolidCollisions/ContentView.swift:12 ContentView
ManipulateWithSolidCollisions/DemoView.swift:12 DemoView
ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsComponent.swift:12 ManipulateWithSolidCollisionsComponent
ManipulateWithSolidCollisions/ECS/ManipulateWithSolidCollisionsSystem.swift:11 ManipulateWithSolidCollisionsSystem
ManipulateWithSolidCollisions/ECS/ResetTransformComponent.swift:10 ResetTransformComponent
ManipulateWithSolidCollisions/ECS/ResetTransformSystem.swift:12 ResetTransformSystem