Finding the sharpest image in a sequence of captured images
At a glance
| Item | Summary |
|---|---|
| Purpose | Share image data between vDSP and vImage to compute the sharpest image from a bracketed photo sequence. |
| App architecture | A Swift sample with the source-visible chain AccelerateBlurDetectionApp → BlurDetectorView → BlurDetectorResultModel → BlurDetectionItemRenderer → Accelerate APIs. |
| Main patterns | Protocol-oriented abstraction, Delegate or data-source callbacks, SwiftUI environment injection, Publisher-backed observable state |
| Project style | 7 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: DispatchQueue(label:), Task, DispatchQueue.main.async; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published. |
| Key frameworks/packages | SwiftUI, AVFoundation, Combine, UIKit, Accelerate; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── AccelerateBlurDetection/
│ ├── AccelerateBlurDetectionApp.swift
│ ├── BlurDetector.swift
│ ├── BlurDetectorResultModel.swift
│ ├── PreviewView.swift
│ ├── BlurDetectionItemRenderer.swift
│ ├── BlurDetectorView.swift
│ ├── BlurDetectorResultsList.swift
│ ├── Base.lproj/
│ │ └── LaunchScreen.storyboard
│ └── Info.plist
├── AccelerateBlurDetection.xcodeproj/
│ ├── .xcodesamplecode.plist
│ └── project.pbxproj
└── Configuration/
└── SampleCode.xcconfig
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 11 source declaration(s).
Overall architecture
flowchart LR
N1["AccelerateBlurDetectionApp"]
N2["BlurDetectorView"]
N3["BlurDetectorResultModel"]
N4["BlurDetectionItemRenderer"]
N5["Accelerate APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
AccelerateBlurDetection/AccelerateBlurDetectionApp.swift:10 — architecture anchor
@main
struct AccelerateBlurDetectionApp: App {
@StateObject private var blurDetectorResultModel = BlurDetectorResultModel()
@StateObject private var blurDetector = BlurDetector()
var body: some Scene {
WindowGroup {
BlurDetectorView()
.environmentObject(blurDetectorResultModel)
.environmentObject(blurDetector)
}
}
}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 Accelerate.
Ownership and state
classDiagram
AccelerateBlurDetectionApp *-- BlurDetectorResultModel : blurDetectorResultModel
AccelerateBlurDetectionApp *-- BlurDetector : blurDetector
BlurDetector *-- Array : laplacian
BlurDetector *-- AVCaptureSession : captureSession
Ownership evidence
AccelerateBlurDetection/AccelerateBlurDetectionApp.swift:13 — stored dependency or nearest verified ownership anchor
@main
struct AccelerateBlurDetectionApp: App {
// ...
@StateObject private var blurDetectorResultModel = BlurDetectorResultModel()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AccelerateBlurDetectionApp |
BlurDetectorResultModel (blurDetectorResultModel) |
owns wrapper-managed state | Owning lexical scope |
AccelerateBlurDetectionApp |
BlurDetector (blurDetector) |
owns wrapper-managed state | Owning lexical scope |
BlurDetector |
Array (laplacian) |
owns value state | Initialized by the owner; the binding is immutable |
BlurDetector |
AVCaptureSession (captureSession) |
creates and retains | Initialized by the owner; the binding is immutable |
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(label:) |
The source constructs a dispatch queue; its label alone does not prove a thread. | AccelerateBlurDetection/BlurDetector.swift:28 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | AccelerateBlurDetection/BlurDetector.swift:216 |
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | AccelerateBlurDetection/BlurDetector.swift:281 |
@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
AccelerateBlurDetection/BlurDetector.swift:28 — representative execution boundary
class BlurDetector: NSObject, ObservableObject {
// ...
let sessionQueue = DispatchQueue(label: "session queue")
// ...
}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 | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | AccelerateBlurDetection/AccelerateBlurDetectionApp.swift:13 |
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | AccelerateBlurDetection/BlurDetector.swift:15 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | AccelerateBlurDetection/BlurDetectorResultModel.swift:24 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | AccelerateBlurDetection/AccelerateBlurDetectionApp.swift:8 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | AccelerateBlurDetection/BlurDetectionItemRenderer.swift:8 |
| Source import | Combine |
The cited file imports this module; runtime use and architectural role are not inferred. | AccelerateBlurDetection/BlurDetector.swift:12 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | AccelerateBlurDetection/BlurDetector.swift:10 |
| Source import | Accelerate |
The cited file imports this module; runtime use and architectural role are not inferred. | AccelerateBlurDetection/BlurDetector.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
AccelerateBlurDetection/BlurDetector.swift:312 — representative type boundary
protocol BlurDetectorResultsDelegate: AnyObject {
func itemProcessed(_ item: BlurDetectionResult)
func finishedProcessing()
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AccelerateBlurDetectionApp |
Application entry and top-level composition | App |
BlurDetectorResultsDelegate |
Defines a capability or collaboration contract | AnyObject |
BlurDetectorResultModel |
Feature data or observable state | ObservableObject, BlurDetectorResultsDelegate |
PreviewView |
User-interface presentation and input forwarding | UIViewRepresentable |
UIPreviewView |
User-interface presentation and input forwarding | UIView |
BlurDetectionItemRenderer |
Owns drawing, GPU, or presentation processing | View |
BlurDetectorView |
User-interface presentation and input forwarding | View |
BlurDetector |
Owns feature behavior and collaborator lifecycle | NSObject, ObservableObject |
BlurDetectionResult |
Represents the result of an operation | Concrete collaborators/imported frameworks |
Mode |
Defines a closed set of feature states or choices | Concrete collaborators/imported frameworks |
The source explicitly defines local protocol relationships: BlurDetectorResultModel → BlurDetectorResultsDelegate.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
blurDetectorResultModel (AccelerateBlurDetection/AccelerateBlurDetectionApp.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. |
blurDetector (AccelerateBlurDetection/AccelerateBlurDetectionApp.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. |
configureSession (AccelerateBlurDetection/BlurDetector.swift:35) |
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. |
BlurDetectorResultModel (AccelerateBlurDetection/BlurDetectorResultModel.swift:8) |
implicit internal |
No explicit modifier means the Swift declaration is internal to the module. | Inference: app-target collaboration needs no exported library surface. |
Reference code
AccelerateBlurDetection/AccelerateBlurDetectionApp.swift:13 — representative boundary
@main
struct AccelerateBlurDetectionApp: App {
// ...
@StateObject private var blurDetectorResultModel = BlurDetectorResultModel()
// ...
}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 | AccelerateBlurDetectionApp |
The source’s App suffix makes this role explicit. |
| Receives callback-driven events | BlurDetectorResultsDelegate |
The source’s Delegate suffix makes this role explicit. |
| Feature data or observable state | BlurDetectorResultModel |
The source’s Model suffix makes this role explicit. |
| Owns drawing, GPU, or presentation processing | BlurDetectionItemRenderer |
The source’s Renderer suffix makes this role explicit. |
| User-interface presentation and input forwarding | BlurDetectorView, PreviewView, UIPreviewView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Protocol-oriented abstraction | AccelerateBlurDetection/BlurDetectorResultModel.swift:16 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | AccelerateBlurDetection/BlurDetectorResultModel.swift:16 |
Callback protocols invert event delivery back into the sample’s owner. |
| SwiftUI environment injection | AccelerateBlurDetection/BlurDetectorView.swift:14 |
The environment supplies state or a capability without threading it through every initializer. |
| Publisher-backed observable state | AccelerateBlurDetection/BlurDetectorResultModel.swift:26 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: AccelerateBlurDetectionApp; Delegate: BlurDetectorResultsDelegate; Model: BlurDetectorResultModel; Renderer: BlurDetectionItemRenderer; View: BlurDetectorView, PreviewView, UIPreviewView.
- Protocols:
BlurDetectorResultsDelegate. - Methods:
configure,configureSession,takePhoto,makeImage,rotate,only,photoOutput,processImage. - Files:
AccelerateBlurDetection/AccelerateBlurDetectionApp.swift,AccelerateBlurDetection/BlurDetector.swift,AccelerateBlurDetection/BlurDetectorResultModel.swift,AccelerateBlurDetection/PreviewView.swift,AccelerateBlurDetection/BlurDetectionItemRenderer.swift,AccelerateBlurDetection/BlurDetectorView.swift.
Architecture takeaways
AccelerateBlurDetectionAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, AVFoundation, UIKit, Accelerate 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 |
|---|---|
AccelerateBlurDetection/AccelerateBlurDetectionApp.swift |
Cited implementation, SwiftUI state property wrapper, SwiftUI, AccelerateBlurDetectionApp |
AccelerateBlurDetection/BlurDetector.swift |
BlurDetectorResultsDelegate, Cited implementation, DispatchQueue(label:), Task, DispatchQueue.main.async, ObservableObject, Combine, UIKit, Accelerate, BlurDetector, BlurDetectionResult |
AccelerateBlurDetection/BlurDetectorResultModel.swift |
BlurDetectorResultModel, Cited implementation, @Published, Mode |
AccelerateBlurDetection/BlurDetectorView.swift |
Cited implementation, BlurDetectorView |
AccelerateBlurDetection/BlurDetectionItemRenderer.swift |
AVFoundation, BlurDetectionItemRenderer |
AccelerateBlurDetection/PreviewView.swift |
PreviewView, UIPreviewView |
AccelerateBlurDetection/BlurDetectorResultsList.swift |
BlurDetectorResultsList |