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.

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 {
    // ...
}

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.

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 AppDelegate
ScanningApp/Controllers/ShareScanViewController.swift ShareScanViewController
ScanningApp/Controllers/ViewController.swift ViewController
ScanningApp/Controllers/Scan.swift Scan, State
ScanningApp/Utility Extensions/Utilities.swift Axis, PlaneDrag, Ray
ScanningApp/Controllers/TestRun.swift TestRun
ScanningApp/Controllers/ViewController+ApplicationState.swift State
ScanningApp/3D UI and Visualizations /BoundingBox.swift BoundingBox, SideDrag
ScanningApp/3D UI and Visualizations /BoundingBoxSide.swift BoundingBoxSide, Position
ScanningApp/Views/MessageLabel.swift Message, MessageLabel