Sample CodeiOS, iPadOSReviewed 2026-07-21View on Apple Developer

Altering RealityKit Rendering with Shader Functions

At a glance

Item Summary
Purpose Create rendering effects by writing surface shaders and geometry modifiers.
App architecture A C/Objective-C header, Metal, Swift sample with the source-visible chain PopAppContentViewCoordinatorRealityKit APIs.
Main patterns Coordinator
Project style 12 scanned source file(s) across C/Objective-C header, Metal, Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue(label:), Task, await suspension point, @MainActor, Task closure isolated to MainActor; none alone proves a background thread.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages RealityKit, Foundation, metal_stdlib, SwiftUI, ARKit; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── Pop/
    ├── PopApp.swift
    ├── UI/
    │   ├── ContentView.swift
    │   ├── RealityView.swift
    │   └── RealityViewContainer.swift
    ├── ApplicationActions.swift
    ├── Entity+Utilities.swift
    └── Metal Shaders/
        ├── CustomMaterialHelpers.h
        ├── CustomMaterialHelpers.metal
        ├── DissolveSurfaceShader.metal
        ├── ExpandGeometryModifier.metal
        ├── UVHelpers.h
        └── UVHelpers.metal

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 4 project/configuration file(s) and 7 source declaration(s).

Overall architecture

Reference code

Pop/PopApp.swift:10 — architecture anchor

@main
@available(iOS 15.0, *)
struct PopApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

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

Ownership evidence

Pop/UI/ContentView.swift:16 — stored dependency or nearest verified ownership anchor

@available(iOS 15.0, *)
struct ContentView: View {
    let maxTapDistance = CGFloat(10)
    // ...
}
Owner Object or state Relationship Mutation authority
ContentView CGFloat (maxTapDistance) owns value state Initialized by the owner; the binding is immutable
ResetButton String (title) owns value state App/module collaborators
ResetButton String (logMessage) owns value state App/module collaborators
RealityView ARCoachingOverlayView (coachingView) 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.

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
Queue scheduling DispatchQueue(label:) The source constructs a dispatch queue; its label alone does not prove a thread. Pop/ApplicationActions.swift:21
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. Pop/UI/RealityView.swift:67
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. Pop/UI/RealityView.swift:68
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. Pop/UI/RealityView.swift:100
Main isolation Task closure isolated to MainActor The cited operation explicitly enters a main-actor-isolated region. Pop/UI/RealityView.swift:100

@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

Pop/ApplicationActions.swift:21 — representative execution boundary

@available(iOS 15.0, *)
struct ApplicationActions {
    // ...
    let playerQueue = DispatchQueue(label: "com.apple.samplecode.player")
    // ...
}

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
Source import RealityKit The cited file imports this module; runtime use and architectural role are not inferred. Pop/Entity+Utilities.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Pop/ApplicationActions.swift:9
Source import metal_stdlib The cited file imports this module; runtime use and architectural role are not inferred. Pop/Metal Shaders/CustomMaterialHelpers.h:16
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. Pop/PopApp.swift:8
Source import ARKit The cited file imports this module; runtime use and architectural role are not inferred. Pop/UI/ContentView.swift:12
Source import MetalKit The cited file imports this module; runtime use and architectural role are not inferred. Pop/UI/ContentView.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

Pop/PopApp.swift:12 — representative type boundary

@main
@available(iOS 15.0, *)
struct PopApp: App {
    // ...
            ContentView()
    // ...
}
Type Responsibility Depends on or conforms to
PopApp Application entry and top-level composition App
ContentView User-interface presentation and input forwarding View
RealityView User-interface presentation and input forwarding ARView
Coordinator Cross-object flow or session coordination NSObject
ResetButton Represents a feature value or composable behavior View
RealityViewContainer Represents a feature value or composable behavior UIViewRepresentable
ApplicationActions 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
userTapped (Pop/UI/RealityView.swift:60) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
resetRobots (Pop/UI/RealityView.swift:73) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
incrementPopProgress (Pop/UI/RealityView.swift:90) 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.
initializeMetal (Pop/UI/RealityView.swift:116) 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

Pop/UI/RealityView.swift:60 — representative boundary

    public func userTapped(at point: CGPoint) {
        // ...
                print("Tapped entity is not a robot.")
        // ...
    }

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 PopApp The source’s App suffix makes this role explicit.
Cross-object flow or session coordination Coordinator The source’s Coordinator suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, RealityView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Coordinator Pop/UI/RealityViewContainer.swift:34 A role-named coordinator centralizes cross-object flow.

Naming conventions

  • Types: App: PopApp; Coordinator: Coordinator; View: ContentView, RealityView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: setup, userTapped, resetRobots, incrementPopProgress, initializeMetal, configureWorldTracking, setUpCoachingOverlay, layoutRobots.
  • Files: Pop/PopApp.swift, Pop/UI/ContentView.swift, Pop/UI/RealityView.swift, Pop/UI/RealityViewContainer.swift, Pop/ApplicationActions.swift.

Architecture takeaways

  • PopApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches RealityKit, metal_stdlib, 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
Pop/PopApp.swift Cited implementation, PopApp, SwiftUI
Pop/UI/ContentView.swift Cited implementation, ARKit, MetalKit, ContentView, ContentView_Previews, ResetButton
Pop/UI/RealityView.swift Cited implementation, Task, await suspension point, @MainActor, Task closure isolated to MainActor, RealityView
Pop/UI/RealityViewContainer.swift Coordinator, RealityViewContainer
Pop/ApplicationActions.swift DispatchQueue(label:), Foundation, ApplicationActions
Pop/Entity+Utilities.swift RealityKit, Feature implementation
Pop/Metal Shaders/CustomMaterialHelpers.h metal_stdlib, Feature implementation
Pop/Metal Shaders/CustomMaterialHelpers.metal Feature implementation
Pop/Metal Shaders/DissolveSurfaceShader.metal Feature implementation
Pop/Metal Shaders/ExpandGeometryModifier.metal Feature implementation
Pop/Metal Shaders/UVHelpers.h Feature implementation
Pop/Metal Shaders/UVHelpers.metal Feature implementation