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

Scanning and Detecting 3D Objects

At a glance

Item Summary
Purpose Record spatial features of real-world objects, then use the results to find those objects in the user’s environment and trigger AR content.
App architecture A Metal, Swift sample with the source-visible chain AppDelegateShareScanViewControllerARKit APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks
Project style 31 scanned source file(s) across Metal, Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue.main.async, DispatchQueue.global.async; none alone proves a background thread.
State/event model Source-visible mechanisms: NotificationCenter.
Key frameworks/packages ARKit, Foundation, UIKit, SceneKit, AVFoundation; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── ScanningApp/
    ├── Controllers/
    │   ├── AppDelegate.swift
    │   ├── ShareScanViewController.swift
    │   ├── ViewController.swift
    │   ├── Scan.swift
    │   ├── TestRun.swift
    │   ├── ViewController+ApplicationState.swift
    │   ├── ViewController+Gestures.swift
    │   └── ViewController+NavigationBar.swift
    ├── Utility Extensions/
    │   └── Utilities.swift
    ├── 3D UI and Visualizations /
    │   ├── BoundingBox.swift
    │   └── BoundingBoxSide.swift
    └── Views/
        └── MessageLabel.swift

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

Overall architecture

Reference code

ScanningApp/Controllers/AppDelegate.swift:11 — architecture anchor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    // ...
    var window: UIWindow?
    // ...
}

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

ScanningApp/3D UI and Visualizations /BoundingBox.swift:13 — stored dependency or nearest verified ownership anchor

class BoundingBox: SCNNode {
    // ...
    static let extentChangedNotification = Notification.Name("BoundingBoxExtentChanged")
    // ...
}
Owner Object or state Relationship Mutation authority
BoundingBox Notification (extentChangedNotification) stores or receives Initialized by the owner; the binding is immutable
BoundingBox Notification (positionChangedNotification) stores or receives Initialized by the owner; the binding is immutable
BoundingBox Notification (scanPercentageChangedNotification) stores or receives Initialized by the owner; the binding is immutable
BoundingBox Extent (extent) 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.main.async The source addresses the main dispatch queue. ScanningApp/Controllers/ViewController+ApplicationState.swift:133
Queue scheduling DispatchQueue.global.async The source addresses a global dispatch queue; no stable thread identity is implied. ScanningApp/Controllers/ViewController.swift:331

@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

ScanningApp/Controllers/ViewController+ApplicationState.swift:133 — representative execution boundary

        DispatchQueue.main.async {
            // ...
            case .ready:
            // ...
        }

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 NotificationCenter NotificationCenter distributes named process-local events. ScanningApp/3D UI and Visualizations /BoundingBox.swift:23
Source import ARKit The cited file imports this module; runtime use and architectural role are not inferred. ScanningApp/3D UI and Visualizations /BoundingBox.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. ScanningApp/3D UI and Visualizations /BoundingBox.swift:8
Source import UIKit The cited file imports this module; runtime use and architectural role are not inferred. ScanningApp/3D UI and Visualizations /Tile.swift:8
Source import SceneKit The cited file imports this module; runtime use and architectural role are not inferred. ScanningApp/3D UI and Visualizations /BoundingBoxSide.swift:9
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. ScanningApp/Views/FlashlightButton.swift:9

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

ScanningApp/3D UI and Visualizations /PointCloud+CreateVisualization.swift:11 — representative type boundary

protocol PointCloud {
    func createVisualization(for points: [SIMD3<Float>], color: UIColor, size: CGFloat) -> SCNGeometry?
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
ShareScanViewController View lifecycle, callbacks, and feature coordination UIActivityViewController
ViewController View lifecycle, callbacks, and feature coordination UIViewController, ARSCNViewDelegate, ARSessionDelegate, UIDocumentPickerDelegate
PointCloud Defines a capability or collaboration contract Concrete collaborators/imported frameworks
Scan Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
State Represents mutable feature state Concrete collaborators/imported frameworks
Axis Defines a closed set of feature states or choices Concrete collaborators/imported frameworks
PlaneDrag Represents a feature value or composable behavior Concrete collaborators/imported frameworks
Ray Represents a feature value or composable behavior Concrete collaborators/imported frameworks
TestRun Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: DetectedPointCloudPointCloud, ScannedPointCloudPointCloud.

Access control

Symbol Access Verified effect Likely rationale
maxDistanceToFocusPoint (ScanningApp/3D UI and Visualizations /BoundingBox.swift:38) 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.
minSize (ScanningApp/3D UI and Visualizations /BoundingBox.swift:40) 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.
currentSideDrag (ScanningApp/3D UI and Visualizations /BoundingBox.swift:49) 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.
currentSidePlaneDrag (ScanningApp/3D UI and Visualizations /BoundingBox.swift:51) 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

ScanningApp/3D UI and Visualizations /BoundingBox.swift:38 — representative boundary

class BoundingBox: SCNNode {
    // ...
    private var maxDistanceToFocusPoint: Float = 0.05
    // ...
}

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
View lifecycle, callbacks, and feature coordination ShareScanViewController, ViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization ScanningApp/Controllers/ShareScanViewController.swift:10 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction ScanningApp/3D UI and Visualizations /DetectedPointCloud.swift:11 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks ScanningApp/Controllers/AppDelegate.swift:12 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: Controller: ShareScanViewController, ViewController; Delegate: AppDelegate.
  • Protocols: PointCloud.
  • Methods: application, applicationWillEnterForeground, applicationWillResignActive, applicationDidBecomeActive, viewWillAppear, viewWillDisappear, viewDidLoad, viewDidLayoutSubviews.
  • Files: ScanningApp/Controllers/AppDelegate.swift, ScanningApp/Controllers/ShareScanViewController.swift, ScanningApp/Controllers/ViewController.swift, ScanningApp/Controllers/Scan.swift, ScanningApp/Controllers/TestRun.swift, ScanningApp/3D UI and Visualizations /BoundingBox.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches ARKit, UIKit, SceneKit, AVFoundation 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
ScanningApp/Controllers/AppDelegate.swift Cited implementation, AppDelegate
ScanningApp/3D UI and Visualizations /BoundingBox.swift Cited implementation, NotificationCenter, ARKit, Foundation, BoundingBox, SideDrag
ScanningApp/3D UI and Visualizations /PointCloud+CreateVisualization.swift PointCloud
ScanningApp/Controllers/ShareScanViewController.swift ShareScanViewController
ScanningApp/3D UI and Visualizations /DetectedPointCloud.swift Cited implementation, DetectedPointCloud
ScanningApp/Controllers/ViewController+ApplicationState.swift DispatchQueue.main.async, State
ScanningApp/Controllers/ViewController.swift DispatchQueue.global.async, ViewController
ScanningApp/3D UI and Visualizations /Tile.swift UIKit, Tile
ScanningApp/3D UI and Visualizations /BoundingBoxSide.swift SceneKit, BoundingBoxSide, Position
ScanningApp/Views/FlashlightButton.swift AVFoundation, FlashlightButton
ScanningApp/Controllers/Scan.swift Scan, State
ScanningApp/Utility Extensions/Utilities.swift Axis, PlaneDrag, Ray
ScanningApp/Controllers/TestRun.swift TestRun
ScanningApp/Views/MessageLabel.swift Message, MessageLabel
ScanningApp/Controllers/ViewController+Gestures.swift Feature implementation
ScanningApp/Controllers/ViewController+NavigationBar.swift Feature implementation