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.

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.

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 PointCloudDepthSample
pointCloudSample/ARDataProvider.swift MetalTextureContent, ARProvider
pointCloudSample/ARReceiver.swift ARDataReceiver, ARData, ARReceiver
pointCloudSample/MetalPointCloud.swift CoordinatorPointCloud, CameraModes, MetalPointCloud
pointCloudSample/MetalViewSample.swift Texture, MetalDepthView, MtkView_Previews
pointCloudSample/MetalTextureViewCoefs.swift MTKCoordinator, MetalTextureViewCoefs
pointCloudSample/MetalTextureViewConfidence.swift CoordinatorConfidence, MetalTextureViewConfidence
pointCloudSample/MetalTextureViewDepth.swift CoordinatorDepth, MetalTextureViewDepth
pointCloudSample/EnvironmentVariables.swift EnvironmentVariables
pointCloudSample/shaders.metal Feature implementation