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

Displaying a point cloud using scene depth

At a glance

Item Summary
Purpose Present a visualization of the physical environment by placing points based a scene’s depth data.
App architecture A Metal, Swift sample with the source-visible chain PointCloudDepthSampleMetalDepthViewMTKCoordinatorARProviderARKit APIs.
Main patterns Protocol-oriented abstraction, Delegate or data-source callbacks, Coordinator, Binding-based state propagation
Project style 10 scanned source file(s) across Metal, Swift, organized around ranked entry, type, and file boundaries.
Execution model No structured execution marker indexed; callback threading requires source review.
State/event model Source-visible mechanisms: SwiftUI state property wrapper.
Key frameworks/packages Foundation, SwiftUI, Metal, MetalKit, ARKit; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── pointCloudSample/
│   ├── PointCloudDepthSample.swift
│   ├── ARDataProvider.swift
│   ├── ARReceiver.swift
│   ├── MetalPointCloud.swift
│   ├── MetalViewSample.swift
│   ├── MetalTextureViewCoefs.swift
│   ├── MetalTextureViewConfidence.swift
│   ├── MetalTextureViewDepth.swift
│   ├── EnvironmentVariables.swift
│   └── shaders.metal
├── Configuration/
│   └── SampleCode.xcconfig
└── pointCloudSample.xcodeproj/
    └── .xcodesamplecode.plist

Structure observations

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

Overall architecture

Reference code

pointCloudSample/PointCloudDepthSample.swift:9 — architecture anchor

@main
struct PointCloudDepthSample: App {
    var body: some Scene {
        WindowGroup {
            MetalDepthView()
        }
    }
}

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

Ownership and state

Ownership evidence

pointCloudSample/ARDataProvider.swift:17 — stored dependency or nearest verified ownership anchor

final class MetalTextureContent {
    var texture: MTLTexture?
}
Owner Object or state Relationship Mutation authority
MetalTextureContent MTLTexture (texture) stores or receives App/module collaborators
ARProvider Float (guidedFilterEpsilon) owns value state Initialized by the owner; the binding is immutable
ARProvider ARReceiver (arReceiver) creates and retains Initialized by the owner; the binding is immutable
ARProvider ARData (lastArData) 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.

No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.

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

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 SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. pointCloudSample/MetalPointCloud.swift:26
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. pointCloudSample/ARDataProvider.swift:8
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. pointCloudSample/ARDataProvider.swift:9
Source import Metal The cited file imports this module; runtime use and architectural role are not inferred. pointCloudSample/EnvironmentVariables.swift:9
Source import MetalKit The cited file imports this module; runtime use and architectural role are not inferred. pointCloudSample/MetalPointCloud.swift:10
Source import ARKit The cited file imports this module; runtime use and architectural role are not inferred. pointCloudSample/ARDataProvider.swift:11
Source import Combine The cited file imports this module; runtime use and architectural role are not inferred. pointCloudSample/ARDataProvider.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

pointCloudSample/ARReceiver.swift:14 — representative type boundary

protocol ARDataReceiver: AnyObject {
    func onNewARData(arData: ARData)
}
Type Responsibility Depends on or conforms to
ARProvider Supplies a capability or framework resource ARDataReceiver
MetalDepthView User-interface presentation and input forwarding View
MTKCoordinator Cross-object flow or session coordination NSObject, MTKViewDelegate
ARDataReceiver Defines a capability or collaboration contract AnyObject
PointCloudDepthSample Represents a feature value or composable behavior App
MetalTextureContent Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
ARData Represents feature data Concrete collaborators/imported frameworks
ARReceiver Owns feature behavior and collaborator lifecycle NSObject, ARSessionDelegate
CoordinatorPointCloud Owns feature behavior and collaborator lifecycle MTKCoordinator
CameraModes Defines a closed set of feature states or choices Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: ARProviderARDataReceiver.

Access control

Symbol Access Verified effect Likely rationale
isToUpsampleDepth (pointCloudSample/ARDataProvider.swift:76) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
isUseSmoothedDepthForUpsampling (pointCloudSample/ARDataProvider.swift:83) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
EnvironmentVariables (pointCloudSample/EnvironmentVariables.swift:19) 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.
selectedConfidence (pointCloudSample/MetalViewSample.swift:57) 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

pointCloudSample/ARDataProvider.swift:76 — representative boundary

    public var isToUpsampleDepth: Bool = false {
        didSet {
            processLastArData()
        }
    }

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
Cross-object flow or session coordination MTKCoordinator The source’s Coordinator suffix makes this role explicit.
Supplies a capability or framework resource ARProvider The source’s Provider suffix makes this role explicit.
User-interface presentation and input forwarding MetalDepthView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Protocol-oriented abstraction pointCloudSample/ARDataProvider.swift:41 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks pointCloudSample/ARReceiver.swift:30 Callback protocols invert event delivery back into the sample’s owner.
Coordinator pointCloudSample/MetalTextureViewCoefs.swift:14 A role-named coordinator centralizes cross-object flow.
Binding-based state propagation pointCloudSample/MetalPointCloud.swift:26 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: Coordinator: MTKCoordinator; Provider: ARProvider; View: MetalDepthView.
  • Protocols: ARDataReceiver.
  • Methods: texture, createTexture, start, pause, onNewARData, processLastArData, session, makePerspectiveMatrixProjection.
  • Files: pointCloudSample/PointCloudDepthSample.swift, pointCloudSample/ARReceiver.swift, pointCloudSample/MetalPointCloud.swift, pointCloudSample/MetalTextureViewCoefs.swift, pointCloudSample/MetalTextureViewConfidence.swift, pointCloudSample/MetalTextureViewDepth.swift.

Architecture takeaways

  • PointCloudDepthSample is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, Metal, MetalKit, 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.
  • Local protocol relationships provide an explicit substitution boundary.

Source map

Source file Relevant symbols
pointCloudSample/PointCloudDepthSample.swift Cited implementation, PointCloudDepthSample
pointCloudSample/ARDataProvider.swift Cited implementation, Foundation, SwiftUI, ARKit, Combine, MetalTextureContent, ARProvider
pointCloudSample/ARReceiver.swift ARDataReceiver, Cited implementation, ARData, ARReceiver
pointCloudSample/EnvironmentVariables.swift Cited implementation, Metal, EnvironmentVariables
pointCloudSample/MetalViewSample.swift Cited implementation, Texture, MetalDepthView, MtkView_Previews
pointCloudSample/MetalTextureViewCoefs.swift MTKCoordinator, MetalTextureViewCoefs
pointCloudSample/MetalPointCloud.swift Cited implementation, SwiftUI state property wrapper, MetalKit, CoordinatorPointCloud, CameraModes, MetalPointCloud
pointCloudSample/MetalTextureViewConfidence.swift CoordinatorConfidence, MetalTextureViewConfidence
pointCloudSample/MetalTextureViewDepth.swift CoordinatorDepth, MetalTextureViewDepth
pointCloudSample/shaders.metal Feature implementation