Scanning objects using Object Capture
At a glance
| Item | Summary |
|---|---|
| Purpose | Implement a full scanning workflow for capturing objects on iOS devices. |
| App architecture | A Swift sample with the source-visible chain GuidedCaptureSampleApp → ContentView → Coordinator → RealityKit APIs. |
| Main patterns | View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Coordinator, Binding-based state propagation |
| Project style | 27 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, DispatchQueue.main.async, Task, await suspension point, DispatchQueue.global.async; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, NotificationCenter, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, os, RealityKit, Foundation, AVFoundation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── GuidedCaptureSample/
└── GuidedCaptureSample/
├── GuidedCaptureSampleApp.swift
├── Views/
│ ├── HelpPageView.swift
│ ├── CaptureOverlayView.swift
│ ├── ReconstructionPrimaryView.swift
│ ├── ModelView.swift
│ ├── OnboardingButtonView.swift
│ ├── BottomOverlayButtons.swift
│ ├── PlayerView.swift
│ ├── TopOverlayButtons.swift
│ └── TutorialPageView.swift
├── AppDataModel.swift
└── CaptureFolderManager.swift
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 5 project/configuration file(s) and 87 source declaration(s).
Overall architecture
flowchart LR
N1["GuidedCaptureSampleApp"]
N2["ContentView"]
N3["Coordinator"]
N4["RealityKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
GuidedCaptureSample/GuidedCaptureSample/GuidedCaptureSampleApp.swift:10 — architecture anchor
@main
struct GuidedCaptureSampleApp: App {
static let subsystem: String = "com.example.apple-samplecode.guided-capture-sample"
var body: some Scene {
WindowGroup {
ContentView()
.environment(AppDataModel.instance)
}
}
}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
classDiagram
GuidedCaptureSampleApp *-- String : subsystem
AppDataModel *-- Logger : logger
AppDataModel *-- AppDataModel : instance
AppDataModel o-- PhotogrammetrySession : photogrammetrySession
Ownership evidence
GuidedCaptureSample/GuidedCaptureSample/GuidedCaptureSampleApp.swift:12 — stored dependency or nearest verified ownership anchor
@main
struct GuidedCaptureSampleApp: App {
static let subsystem: String = "com.example.apple-samplecode.guided-capture-sample"
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
GuidedCaptureSampleApp |
String (subsystem) |
owns value state | Initialized by the owner; the binding is immutable |
AppDataModel |
Logger (logger) |
creates and retains | Initialized by the owner; the binding is immutable |
AppDataModel |
AppDataModel (instance) |
creates and retains | Initialized by the owner; the binding is immutable |
AppDataModel |
PhotogrammetrySession (photogrammetrySession) |
stores or receives | Owning type writes; wider scope can read |
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 |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:16 |
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:106 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:162 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:163 |
| Queue scheduling | DispatchQueue.global.async |
The source addresses a global dispatch queue; no stable thread identity is implied. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:353 |
@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
GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:16 — representative execution boundary
@MainActor
@Observable
class AppDataModel: Identifiable {
static let instance = AppDataModel()
// ...
}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 | @Observable |
Observation macro publishes source-visible changes. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:17 |
| State propagation | NotificationCenter |
NotificationCenter distributes named process-local events. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:98 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | GuidedCaptureSample/GuidedCaptureSample/Views/BottomOverlayButtons.swift:15 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:10 |
| Source import | os |
The cited file imports this module; runtime use and architectural role are not inferred. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:11 |
| Source import | RealityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | GuidedCaptureSample/GuidedCaptureSample/CaptureFolderManager.swift:11 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | GuidedCaptureSample/GuidedCaptureSample/Views/CaptureOverlayView.swift:8 |
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
GuidedCaptureSample/GuidedCaptureSample/Views/CaptureOverlayView.swift:237 — representative type boundary
protocol OverlayButtons {
func isCapturingStarted(state: ObjectCaptureSession.CaptureState) -> Bool
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
GuidedCaptureSampleApp |
Application entry and top-level composition | App |
HelpPageView |
User-interface presentation and input forwarding | View |
CaptureTypesHelpPageView |
User-interface presentation and input forwarding | View |
HowToCaptureHelpPageView |
User-interface presentation and input forwarding | View |
SupportedObjectHelpPageView |
User-interface presentation and input forwarding | View |
EnvironmentHelpPageView |
User-interface presentation and input forwarding | View |
AppDataModel |
Feature data or observable state | Identifiable |
CaptureOverlayView |
User-interface presentation and input forwarding | View |
TutorialView |
User-interface presentation and input forwarding | View |
BoundingBoxGuidanceView |
User-interface presentation and input forwarding | View |
The source explicitly defines local protocol relationships: BottomOverlayButtons → OverlayButtons, TopOverlayButtons → OverlayButtons.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
logger (GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:13) |
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. |
photogrammetrySession (GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:35) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
captureFolderManager (GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:38) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
isSaveDraftEnabled (GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:41) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
Reference code
GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift:13 — representative boundary
private let logger = Logger(subsystem: GuidedCaptureSampleApp.subsystem,
category: "AppDataModel")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 |
|---|---|---|
| Application entry and top-level composition | GuidedCaptureSampleApp |
The source’s App suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | ARQuickLookController |
The source’s Controller suffix makes this role explicit. |
| Cross-object flow or session coordination | Coordinator |
The source’s Coordinator suffix makes this role explicit. |
| Long-lived feature or framework coordination | CaptureFolderManager |
The source’s Manager suffix makes this role explicit. |
| Feature data or observable state | AppDataModel |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | AVPlayerView, AutoDetectionStateView, BoundingBoxGuidanceView, CaptureModeGuidanceView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | GuidedCaptureSample/GuidedCaptureSample/Views/ModelView.swift:23 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | GuidedCaptureSample/GuidedCaptureSample/Views/BottomOverlayButtons.swift:14 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | GuidedCaptureSample/GuidedCaptureSample/Views/ModelView.swift:40 |
Callback protocols invert event delivery back into the sample’s owner. |
| Coordinator | GuidedCaptureSample/GuidedCaptureSample/Views/ModelView.swift:40 |
A role-named coordinator centralizes cross-object flow. |
| Binding-based state propagation | GuidedCaptureSample/GuidedCaptureSample/Views/BottomOverlayButtons.swift:17 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: App: GuidedCaptureSampleApp; Controller: ARQuickLookController; Coordinator: Coordinator; Manager: CaptureFolderManager; Model: AppDataModel; View: AVPlayerView, AutoDetectionStateView, BoundingBoxGuidanceView, CaptureModeGuidanceView, CaptureOverlayView.
- Protocols:
OverlayButtons. - Methods:
endCapture,removeCaptureFolder,setShowOverlaySheets,saveDraft,attachListeners,detachListeners,handleAppTermination,startNewCapture. - Files:
GuidedCaptureSample/GuidedCaptureSample/GuidedCaptureSampleApp.swift,GuidedCaptureSample/GuidedCaptureSample/Views/HelpPageView.swift,GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift,GuidedCaptureSample/GuidedCaptureSample/Views/CaptureOverlayView.swift,GuidedCaptureSample/GuidedCaptureSample/Views/ReconstructionPrimaryView.swift,GuidedCaptureSample/GuidedCaptureSample/Views/ModelView.swift.
Architecture takeaways
GuidedCaptureSampleAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, RealityKit, AVFoundation, AVKit 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 |
|---|---|
GuidedCaptureSample/GuidedCaptureSample/GuidedCaptureSampleApp.swift |
Cited implementation, GuidedCaptureSampleApp |
GuidedCaptureSample/GuidedCaptureSample/Views/CaptureOverlayView.swift |
OverlayButtons, AVFoundation, CaptureOverlayView, TutorialView, LocalizedString, BoundingBoxGuidanceView |
GuidedCaptureSample/GuidedCaptureSample/AppDataModel.swift |
Cited implementation, @MainActor, DispatchQueue.main.async, Task, await suspension point, DispatchQueue.global.async, @Observable, NotificationCenter, SwiftUI, os, RealityKit, AppDataModel, ModelState, CaptureMode |
GuidedCaptureSample/GuidedCaptureSample/Views/ModelView.swift |
ARQuickLookController, Cited implementation, Coordinator, ModelView, QLPreviewControllerWrapper |
GuidedCaptureSample/GuidedCaptureSample/Views/BottomOverlayButtons.swift |
Cited implementation, SwiftUI state property wrapper, BottomOverlayButtons, CaptureButton, LocalizedString, AutoDetectionStateView, ResetBoundingBoxButton, ManualShotButton, HelpButton, CaptureModeButton, NumOfImagesButton, AutoCaptureToggle |
GuidedCaptureSample/GuidedCaptureSample/CaptureFolderManager.swift |
Foundation, CaptureFolderManager, Error |
GuidedCaptureSample/GuidedCaptureSample/Views/HelpPageView.swift |
HelpPageView, LocalizedString, CaptureTypesHelpPageView, HowToCaptureHelpPageView, SupportedObjectHelpPageView, EnvironmentHelpPageView |
GuidedCaptureSample/GuidedCaptureSample/Views/ReconstructionPrimaryView.swift |
ReconstructionPrimaryView, ReconstructionProgressView, LocalizedString, TitleView |
GuidedCaptureSample/GuidedCaptureSample/Views/OnboardingButtonView.swift |
OnboardingButtonView, CreateButton, CancelButton, CameraToggleButton |
GuidedCaptureSample/GuidedCaptureSample/Views/PlayerView.swift |
PlayerView, Coordinator, AVPlayerView |
GuidedCaptureSample/GuidedCaptureSample/Views/TopOverlayButtons.swift |
TopOverlayButtons, CaptureCancelButton, LocalizedString, NextButton, CaptureFolderButton, CaptureModeGuidanceView, VisualEffectRoundedCorner, GalleryView, ThumbnailView |
GuidedCaptureSample/GuidedCaptureSample/Views/TutorialPageView.swift |
Section, TutorialPageView, SectionView |
GuidedCaptureSample/GuidedCaptureSample/Views/CapturePrimaryView.swift |
CapturePrimaryView, GradientBackground |
GuidedCaptureSample/GuidedCaptureSample/Views/PrimaryView.swift |
PrimaryView, CircularProgressView |
GuidedCaptureSample/GuidedCaptureSample/Views/ProgressBarView.swift |
ProgressBarView, LocalizedString |
GuidedCaptureSample/GuidedCaptureSample/OnboardingStateMachine.swift |
OnboardingStateMachine, OnboardingState, OnboardingUserInput, OnboardingError |