Sample CodemacOS, visionOSReviewed 2026-07-21View on Apple Developer

Rendering hover effects in Metal immersive apps

At a glance

Item Summary
Purpose Change the appearance of a rendered onscreen element when a player gazes at it.
App architecture A C/Objective-C header, Metal, Swift sample with the source-visible chain CompositorServicesHoverEffectAppSettingsViewAppModelTileResolvePipelineCompositorServices APIs.
Main patterns Binding-based state propagation, Actor-isolated state
Project style 18 scanned source file(s) across C/Objective-C header, Metal, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── CS_HoverEffect/
    └── CS_HoverEffect/
        ├── App/
        │   ├── CompositorServicesHoverEffectApp.swift
        │   ├── CompositorServicesHoverEffectApp+CompositorLayer.swift
        │   └── CompositorServicesHoverEffectApp+Render.swift
        ├── Data/
        │   ├── DataStructures.swift
        │   ├── AppModel.swift
        │   ├── RenderData+Animate.swift
        │   ├── RenderData.swift
        │   └── RenderData+AssetLoad.swift
        ├── TileResolver/
        │   └── TileResolvePipeline.swift
        ├── Views/
        │   └── SettingsView.swift
        ├── Shaders/
        │   └── Shaders.metal
        └── Extensions/
            └── CompositorLayer+FunctionInit.swift

Structure observations

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

Overall architecture

Reference code

CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp.swift:19 — architecture anchor

@main
struct CompositorServicesHoverEffectApp: App {
    // ...
}

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 Compositor Services.

Ownership and state

Ownership evidence

CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp.swift:22 — stored dependency or nearest verified ownership anchor

@main
struct CompositorServicesHoverEffectApp: App {
    // ...
    @State var appModel = AppModel()
    // ...
}
Owner Object or state Relationship Mutation authority
CompositorServicesHoverEffectApp AppModel (appModel) owns wrapper-managed state App/module collaborators
AppCompositorContent AppModel (appModel) stores or receives App/module collaborators
AppCompositorContent RemoteDeviceIdentifier (remoteDeviceIdentifier) stores or receives Owning lexical scope
DrawCallMaterial MTLTexture (texture) stores or receives 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.

Class and protocol design

CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp.swift:20 — representative type boundary

struct CompositorServicesHoverEffectApp: App {
    // ...
}
Type Responsibility Depends on or conforms to
CompositorServicesHoverEffectApp Application entry and top-level composition App
Scene Scene lifecycle or scene-level composition Concrete collaborators/imported frameworks
AppModel Feature data or observable state Concrete collaborators/imported frameworks
TileResolvePipeline Coordinates a multi-stage processing flow Concrete collaborators/imported frameworks
SettingsView User-interface presentation and input forwarding View
AppCompositorContent Represents a feature value or composable behavior CompositorContent
DrawCallMaterial Represents a feature value or composable behavior Concrete collaborators/imported frameworks
DrawCall Represents a feature value or composable behavior Sendable
ShaderConstants Represents a feature value or composable behavior Hashable
TextureCache Represents a feature value or composable behavior Concrete collaborators/imported frameworks

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
remoteDeviceIdentifier (CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp.swift:76) 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.
loadSkybox (CS_HoverEffect/CS_HoverEffect/Data/RenderData+AssetLoad.swift:38) 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.
loadSkyboxShader (CS_HoverEffect/CS_HoverEffect/Data/RenderData+AssetLoad.swift:54) 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.
load (CS_HoverEffect/CS_HoverEffect/Data/RenderData+AssetLoad.swift:92) 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.

Reference code

CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp.swift:76 — representative boundary

struct AppCompositorContent: CompositorContent {
    // ...
    private var remoteDeviceIdentifier: RemoteDeviceIdentifier?
    // ...
}

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 CompositorServicesHoverEffectApp The source’s App suffix makes this role explicit.
Feature data or observable state AppModel The source’s Model suffix makes this role explicit.
Coordinates a multi-stage processing flow TileResolvePipeline The source’s Pipeline suffix makes this role explicit.
Scene lifecycle or scene-level composition Scene The source’s Scene suffix makes this role explicit.
User-interface presentation and input forwarding SettingsView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Binding-based state propagation CS_HoverEffect/CS_HoverEffect/Views/SettingsView.swift:12 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Actor-isolated state CS_HoverEffect/CS_HoverEffect/Data/DataStructures.swift:30 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: App: CompositorServicesHoverEffectApp; Model: AppModel; Pipeline: TileResolvePipeline; Scene: Scene; View: SettingsView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: add, easeInOutQuad, easeOutSine, animate, tap, updatePipelineState, getDepthState, getRenderTexture.
  • Files: CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp.swift, CS_HoverEffect/CS_HoverEffect/Data/AppModel.swift, CS_HoverEffect/CS_HoverEffect/TileResolver/TileResolvePipeline.swift, CS_HoverEffect/CS_HoverEffect/Views/SettingsView.swift, CS_HoverEffect/CS_HoverEffect/Data/RenderData.swift.

Architecture takeaways

  • CompositorServicesHoverEffectApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches CompositorServices, MetalKit, SwiftUI, ARKit 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
CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp.swift CompositorServicesHoverEffectApp, AppCompositorContent
CS_HoverEffect/CS_HoverEffect/Data/DataStructures.swift DrawCallMaterial, DrawCall, Scene, ShaderConstants, TextureCache
CS_HoverEffect/CS_HoverEffect/Data/AppModel.swift AppModel
CS_HoverEffect/CS_HoverEffect/TileResolver/TileResolvePipeline.swift TileResolvePipeline
CS_HoverEffect/CS_HoverEffect/Views/SettingsView.swift SettingsView
CS_HoverEffect/CS_HoverEffect/Shaders/Shaders.metal VertexIn, VertexOut, FragmentOut
CS_HoverEffect/CS_HoverEffect/Data/RenderData+Animate.swift AnimationState
CS_HoverEffect/CS_HoverEffect/Data/RenderData.swift RenderData
CS_HoverEffect/CS_HoverEffect/Extensions/CompositorLayer+FunctionInit.swift Configuration
CS_HoverEffect/CS_HoverEffect/App/CompositorServicesHoverEffectApp+CompositorLayer.swift Feature implementation