Supporting Continuity Camera in your macOS app
At a glance
| Item | Summary |
|---|---|
| Purpose | Enable high-quality photo and video capture by using an iPhone camera as an external capture device. |
| App architecture | A Swift sample with the source-visible chain ContinuityCamApp → ContentView → PreferredCameraObserver → AVFoundation APIs. |
| Main patterns | SwiftUI environment injection, Binding-based state propagation, 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: @MainActor, Sendable or @Sendable, Task, await suspension point, RunLoop.main; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: ObservableObject, AnyCancellable, @Published, receive(on:). |
| Key frameworks/packages | SwiftUI, AVFoundation, Combine, Foundation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── ContinuityCam/
│ ├── ContinuityCamApp.swift
│ ├── Views/
│ │ ├── ConfigurationView.swift
│ │ ├── MaterialView.swift
│ │ └── CameraPreview.swift
│ ├── Camera.swift
│ ├── ContentView.swift
│ ├── DeviceObservers.swift
│ └── ContinuityCam.entitlements
├── Configuration/
│ └── SampleCode.xcconfig
└── ContinuityCam.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 4 project/configuration file(s) and 17 source declaration(s).
Overall architecture
flowchart LR
N1["ContinuityCamApp"]
N2["ContentView"]
N3["PreferredCameraObserver"]
N4["AVFoundation APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
ContinuityCam/ContinuityCamApp.swift:10 — architecture anchor
@main
struct ContinuityCamApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.navigationTitle("Continuity Camera Sample")
.frame(minWidth: 800, minHeight: 600)
}
}
}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 AVFoundation.
Ownership and state
classDiagram
ConfigurationView *-- CGFloat : sectionSpacing
ConfigurationView o-- Camera : camera
SectionHeader *-- String : title
DevicePickerView *-- String : label
Ownership evidence
ContinuityCam/Views/ConfigurationView.swift:14 — stored dependency or nearest verified ownership anchor
struct ConfigurationView: View {
// ...
let sectionSpacing: CGFloat = 20
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ConfigurationView |
CGFloat (sectionSpacing) |
owns value state | Initialized by the owner; the binding is immutable |
ConfigurationView |
Camera (camera) |
observes externally owned state | The observed object is authoritative |
SectionHeader |
String (title) |
owns value state | Initialized by the owner; the binding is immutable |
DevicePickerView |
String (label) |
owns value state | 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 |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | ContinuityCam/Camera.swift:12 |
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | ContinuityCam/Camera.swift:21 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | ContinuityCam/Camera.swift:101 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | ContinuityCam/Camera.swift:101 |
| Run-loop scheduling | RunLoop.main |
The source refers to the main thread’s run loop, a scheduling/liveness boundary rather than actor isolation. | ContinuityCam/Camera.swift:105 |
@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
ContinuityCam/Camera.swift:12 — representative execution boundary
@MainActor
class Camera: ObservableObject {
// ...
case noVideoDeviceAvailable
// ...
}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 | ObservableObject |
ObservableObject supplies an observation contract. | ContinuityCam/Camera.swift:13 |
| State propagation | AnyCancellable |
A cancellable value records subscription lifetime management. | ContinuityCam/Camera.swift:62 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | ContinuityCam/Camera.swift:65 |
| Combine scheduling | receive(on:) |
receive(on:) selects the scheduler for downstream delivery. |
ContinuityCam/Camera.swift:105 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | ContinuityCam/ContentView.swift:8 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | ContinuityCam/Camera.swift:9 |
| Source import | Combine |
The cited file imports this module; runtime use and architectural role are not inferred. | ContinuityCam/Camera.swift:10 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | ContinuityCam/Camera.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
ContinuityCam/ContinuityCamApp.swift:11 — representative type boundary
@main
struct ContinuityCamApp: App {
// ...
ContentView()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
ContinuityCamApp |
Application entry and top-level composition | App |
ConfigurationView |
User-interface presentation and input forwarding | View |
DevicePickerView |
User-interface presentation and input forwarding | View |
EffectStatusView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
MaterialView |
User-interface presentation and input forwarding | NSViewRepresentable |
VideoEffectsObserver |
Observes and relays feature changes | NSObject, ObservableObject, @unchecked Sendable |
PreferredCameraObserver |
Observes and relays feature changes | NSObject, ObservableObject |
PreviewCamera |
Owns feature behavior and collaborator lifecycle | Camera |
SectionHeader |
Represents a feature value or composable behavior | View |
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 |
|---|---|---|---|
isSetup (ContinuityCam/Camera.swift:29) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
isAuthorized (ContinuityCam/Camera.swift:30) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
isRunning (ContinuityCam/Camera.swift:31) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
session (ContinuityCam/Camera.swift:34) |
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
ContinuityCam/Camera.swift:29 — representative boundary
@MainActor
class Camera: ObservableObject {
// ...
private(set) var isSetup = false
// ...
}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 | ContinuityCamApp |
The source’s App suffix makes this role explicit. |
| Observes and relays feature changes | PreferredCameraObserver, VideoEffectsObserver |
The source’s Observer suffix makes this role explicit. |
| User-interface presentation and input forwarding | ConfigurationView, ContentView, DevicePickerView, EffectStatusView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| SwiftUI environment injection | ContinuityCam/Views/ConfigurationView.swift:105 |
The environment supplies state or a capability without threading it through every initializer. |
| Binding-based state propagation | ContinuityCam/Views/ConfigurationView.swift:87 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
| Publisher-backed observable state | ContinuityCam/DeviceObservers.swift:45 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: ContinuityCamApp; Observer: PreferredCameraObserver, VideoEffectsObserver; View: ConfigurationView, ContentView, DevicePickerView, EffectStatusView, MaterialView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
start,authorize,setup,setupDeviceDiscovery,setupInputs,addInput,resetToDefaultDevices,startSession. - Files:
ContinuityCam/ContinuityCamApp.swift,ContinuityCam/Views/ConfigurationView.swift,ContinuityCam/Camera.swift,ContinuityCam/ContentView.swift,ContinuityCam/Views/MaterialView.swift,ContinuityCam/Views/CameraPreview.swift.
Architecture takeaways
ContinuityCamAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, 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.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
ContinuityCam/ContinuityCamApp.swift |
Cited implementation, ContinuityCamApp |
ContinuityCam/Views/ConfigurationView.swift |
Cited implementation, ConfigurationView, ConfigurationView_Previews, PreviewCamera, SectionHeader, DevicePickerView, EffectStatusView, EffectStatusView_Previews |
ContinuityCam/Camera.swift |
Cited implementation, @MainActor, Sendable or @Sendable, Task, await suspension point, RunLoop.main, ObservableObject, AnyCancellable, @Published, receive(on:), AVFoundation, Combine, Foundation, Camera, Error, State, Device, VideoFormat |
ContinuityCam/DeviceObservers.swift |
Cited implementation, VideoEffectsObserver, PreferredCameraObserver |
ContinuityCam/ContentView.swift |
SwiftUI, ContentView, ContentView_Previews |
ContinuityCam/Views/MaterialView.swift |
MaterialView |
ContinuityCam/Views/CameraPreview.swift |
CameraPreview, CaptureVideoPreview |