Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Implementing playing card overlap and physical characteristics

At a glance

Item Summary
Purpose Add interactive card game behavior for a pile of playing cards with physically realistic stacking and overlapping.
App architecture A Swift sample with the source-visible chain MessyPileExampleAppPlaygroundViewTabletopKit APIs.
Main patterns Delegate or data-source callbacks
Project style 16 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: @MainActor, Task, await suspension point; none alone proves a background thread.
State/event model Source-visible mechanisms: @Observable, SwiftUI state property wrapper.
Key frameworks/packages TabletopKit, RealityKit, SwiftUI, RealityKitContent, Spatial; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── Project/
    ├── MessyPileExample/
    │   ├── MessyPileExampleApp.swift
    │   ├── Views/
    │   │   └── PlaygroundView.swift
    │   ├── Support/
    │   │   ├── CenterOfMassSolver.swift
    │   │   └── ConvexBoundary2D.swift
    │   ├── Entity/
    │   │   └── Playground.swift
    │   ├── Equipment/
    │   │   ├── Card.swift
    │   │   ├── MessyPile.swift
    │   │   ├── Seat.swift
    │   │   ├── Stack.swift
    │   │   └── Table.swift
    │   └── Interaction/
    │       └── Interaction.swift
    └── Packages/
        └── RealityKitContent/
            └── Sources/
                └── RealityKitContent/
                    └── RealityKitContent.swift

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 16 source declaration(s).

Overall architecture

Reference code

Project/MessyPileExample/MessyPileExampleApp.swift:12 — architecture anchor

@main
struct MessyPileExampleApp: App {
    @State var playground = Playground()
    var body: some SwiftUI.Scene {
        WindowGroup {
            PlaygroundView()
                .environment(playground)
        }
        .windowStyle(.volumetric)
        .defaultSize(width: 1, height: 1, depth: 1, in: .meters)
    }
}

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 TabletopKit.

Ownership and state

Ownership evidence

Project/MessyPileExample/MessyPileExampleApp.swift:14 — stored dependency or nearest verified ownership anchor

@main
struct MessyPileExampleApp: App {
    @State var playground = Playground()
    // ...
}
Owner Object or state Relationship Mutation authority
MessyPileExampleApp Playground (playground) owns wrapper-managed state App/module collaborators
PlaygroundView Entity (volumetricRoot) stores or receives Initialized by the owner; the binding is immutable
OrientedBox Pose2D (pose) stores or receives Initialized by the owner; the binding is immutable
OrientedBox Rect3DFloat (boundingBox) stores or receives 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
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. Project/MessyPileExample/Entity/Playground.swift:19
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. Project/MessyPileExample/Views/PlaygroundView.swift:38
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. Project/MessyPileExample/Views/PlaygroundView.swift:38

@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

Project/MessyPileExample/Entity/Playground.swift:19 — representative execution boundary

    @MainActor
    init() {
        let table = Table()
        // ...
    }

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. Project/MessyPileExample/Entity/Playground.swift:12
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. Project/MessyPileExample/MessyPileExampleApp.swift:14
Source import TabletopKit The cited file imports this module; runtime use and architectural role are not inferred. Project/MessyPileExample/Entity/Playground.swift:10
Source import RealityKit The cited file imports this module; runtime use and architectural role are not inferred. Project/MessyPileExample/Entity/Playground.swift:9
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. Project/MessyPileExample/Entity/Playground.swift:8
Source import RealityKitContent The cited file imports this module; runtime use and architectural role are not inferred. Project/MessyPileExample/Equipment/Card.swift:11
Source import Spatial The cited file imports this module; runtime use and architectural role are not inferred. Project/MessyPileExample/MessyPileExampleApp.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Project/MessyPileExample/Views/PlaygroundView.swift:13

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

Project/MessyPileExample/MessyPileExampleApp.swift:13 — representative type boundary

@main
struct MessyPileExampleApp: App {
    @State var playground = Playground()
    // ...
}
Type Responsibility Depends on or conforms to
MessyPileExampleApp Application entry and top-level composition App
PlaygroundView User-interface presentation and input forwarding View
OrientedBox Represents a feature value or composable behavior Concrete collaborators/imported frameworks
CenterOfMassSolver Represents a feature value or composable behavior Concrete collaborators/imported frameworks
Plane3DFloat Represents a feature value or composable behavior Concrete collaborators/imported frameworks
ConvexBoundary2D Represents a feature value or composable behavior Concrete collaborators/imported frameworks
Playground Owns feature behavior and collaborator lifecycle EntityRenderDelegate
Card Represents a feature value or composable behavior EntityEquipment
MessyPile Represents a feature value or composable behavior EntityEquipment
Seat Represents a feature value or composable behavior TableSeat

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
findEdgeIndexSurrounding (Project/MessyPileExample/Support/BoundedConvexHull.swift:116) internal No explicit modifier means the Swift declaration is internal to the module. Inference: the language’s file or module boundary is sufficient for this sample collaboration.
findTopVertexAndRemainingVertices (Project/MessyPileExample/Support/BoundedConvexHull.swift:139) internal No explicit modifier means the Swift declaration is internal to the module. Inference: the language’s file or module boundary is sufficient for this sample collaboration.
findConvexHullPlaneContaining (Project/MessyPileExample/Support/BoundedConvexHull.swift:168) internal No explicit modifier means the Swift declaration is internal to the module. Inference: the language’s file or module boundary is sufficient for this sample collaboration.
makeEdgePlane (Project/MessyPileExample/Support/ConvexBoundary2D.swift:176) internal No explicit modifier means the Swift declaration is internal to the module. Inference: the language’s file or module boundary is sufficient for this sample collaboration.

Reference code

Project/MessyPileExample/Support/BoundedConvexHull.swift:116 — representative boundary

    internal func findEdgeIndexSurrounding(corners: [Point3DFloat],
                                           center: Point3DFloat,
                                           from vertex: Point3DFloat) -> Int {
        let vertexToCenter = center - vertex
        // ...
    }

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 MessyPileExampleApp The source’s App suffix makes this role explicit.
User-interface presentation and input forwarding PlaygroundView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks Project/MessyPileExample/Entity/Playground.swift:13 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: App: MessyPileExampleApp; View: PlaygroundView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: calculateCenterOfMass, clampCenterOfMass, calculateCenterOfContactAndWeight, calculateCentersOfMass, distance, contains, strictlyContains, height.
  • Files: Project/MessyPileExample/MessyPileExampleApp.swift, Project/MessyPileExample/Views/PlaygroundView.swift, Project/MessyPileExample/Support/CenterOfMassSolver.swift, Project/MessyPileExample/Support/ConvexBoundary2D.swift, Project/MessyPileExample/Entity/Playground.swift, Project/MessyPileExample/Equipment/Card.swift.

Architecture takeaways

  • MessyPileExampleApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches TabletopKit, RealityKit, SwiftUI, RealityKitContent 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
Project/MessyPileExample/MessyPileExampleApp.swift Cited implementation, MessyPileExampleApp, SwiftUI state property wrapper, Spatial
Project/MessyPileExample/Support/BoundedConvexHull.swift Cited implementation, BoundedConvexHull
Project/MessyPileExample/Support/ConvexBoundary2D.swift Cited implementation, Plane3DFloat, ConvexBoundary2D
Project/MessyPileExample/Entity/Playground.swift Cited implementation, @MainActor, @Observable, TabletopKit, RealityKit, SwiftUI, Playground
Project/MessyPileExample/Views/PlaygroundView.swift Task, await suspension point, Foundation, PlaygroundView
Project/MessyPileExample/Equipment/Card.swift RealityKitContent, Card
Project/MessyPileExample/Support/CenterOfMassSolver.swift OrientedBox, CenterOfMassSolver
Project/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift Feature implementation
Project/MessyPileExample/Equipment/MessyPile.swift MessyPile
Project/MessyPileExample/Equipment/Seat.swift Seat
Project/MessyPileExample/Equipment/Stack.swift Stack
Project/MessyPileExample/Equipment/Table.swift Table
Project/MessyPileExample/Interaction/Interaction.swift Interaction
Project/MessyPileExample/Support/Geometry2D.swift OrientedRect2DFloat
Project/MessyPileExample/Support/PlaygroundActivity.swift PlaygroundActivity
Project/Packages/RealityKitContent/Package.swift Feature implementation