Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Creating a photogrammetry command-line app

At a glance

Item Summary
Purpose Generate 3D objects from images using RealityKit Object Capture.
App architecture A Swift sample centered on HelloPhotogrammetry, with direct use of ArgumentParser, Metal, RealityKit.
Main patterns No named application pattern supported by the extracted structure
Project style 1 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: Task, await suspension point, RunLoop.main; none alone proves a background thread.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages ArgumentParser, Foundation, Metal, os, RealityKit; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── HelloPhotogrammetry/
│   └── main.swift
├── Configuration/
│   └── SampleCode.xcconfig
└── HelloPhotogrammetry.xcodeproj/
    ├── .xcodesamplecode.plist
    └── project.pbxproj

Structure observations

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

Overall architecture

Reference code

HelloPhotogrammetry/main.swift:19 — architecture anchor

struct HelloPhotogrammetry: ParsableCommand {
    // ...
    private typealias Configuration = PhotogrammetrySession.Configuration
    // ...
}

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

HelloPhotogrammetry/main.swift:14 — stored dependency or nearest verified ownership anchor

private let logger = Logger(subsystem: "com.apple.sample.photogrammetry",
                            category: "HelloPhotogrammetry")
Owner Object or state Relationship Mutation authority
main Logger (logger) creates and retains Initialized by the owner; the binding is immutable
HelloPhotogrammetry CommandConfiguration (configuration) creates and retains Initialized by the owner; the binding is immutable
HelloPhotogrammetry String (inputFolder) owns value state Owning lexical scope
HelloPhotogrammetry String (outputFilename) owns value state Owning lexical scope

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
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. HelloPhotogrammetry/main.swift:77
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. HelloPhotogrammetry/main.swift:79
Run-loop scheduling RunLoop.main The source refers to the main thread’s run loop, a scheduling/liveness boundary rather than actor isolation. HelloPhotogrammetry/main.swift:127

@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

HelloPhotogrammetry/main.swift:77 — representative execution boundary

        let waiter = Task {
            // ...
                        case .processingComplete:
            // ...
        }

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 ArgumentParser The cited file imports this module; runtime use and architectural role are not inferred. HelloPhotogrammetry/main.swift:8
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. HelloPhotogrammetry/main.swift:9
Source import Metal The cited file imports this module; runtime use and architectural role are not inferred. HelloPhotogrammetry/main.swift:12
Source import os The cited file imports this module; runtime use and architectural role are not inferred. HelloPhotogrammetry/main.swift:10
Source import RealityKit The cited file imports this module; runtime use and architectural role are not inferred. HelloPhotogrammetry/main.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

HelloPhotogrammetry/main.swift:19 — representative type boundary

struct HelloPhotogrammetry: ParsableCommand {
    // ...
    private typealias Configuration = PhotogrammetrySession.Configuration
    // ...
}
Type Responsibility Depends on or conforms to
HelloPhotogrammetry Represents a feature value or composable behavior ParsableCommand
IllegalOption Defines a closed set of feature states or choices Swift.Error

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
logger (HelloPhotogrammetry/main.swift:14) 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.
configuration (HelloPhotogrammetry/main.swift:24) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
inputFolder (HelloPhotogrammetry/main.swift:28) 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.
outputFilename (HelloPhotogrammetry/main.swift:31) 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

HelloPhotogrammetry/main.swift:14 — representative boundary

private let logger = Logger(subsystem: "com.apple.sample.photogrammetry",
                            category: "HelloPhotogrammetry")

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
Feature and framework orchestration HelloPhotogrammetry The sample keeps the demonstrated path in its primary concrete type.

Design patterns

Pattern Source evidence Purpose or tradeoff
No named application pattern HelloPhotogrammetry/main.swift:19 The verified source directly composes concrete framework types; this document avoids forcing a pattern name.

Naming conventions

  • Types: feature-specific names rather than reusable layer suffixes.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: run, makeConfigurationFromArguments, makeRequestFromArguments, handleRequestComplete, handleRequestProgress.
  • Files: feature/project roles rather than a strict one-type-per-file rule.

Architecture takeaways

  • HelloPhotogrammetry is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches ArgumentParser, Metal, RealityKit 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
HelloPhotogrammetry/main.swift HelloPhotogrammetry, Cited implementation, Task, await suspension point, RunLoop.main, ArgumentParser, Foundation, Metal, os, RealityKit, IllegalOption