Capturing screen content on iOS
At a glance
| Item | Summary |
|---|---|
| Purpose | Capture the full display or only the app’s own content through the system content-sharing picker, then record to disk, keep a rolling clip buffer, add microphone or front-camera effects, and preview results in SCRecordingEditor. |
| App architecture | ContentView creates one @MainActor CaptureManager (an ObservableObject) and injects it with .environmentObject. CaptureManager owns the SCStream and its outputs. A separate, non-main-actor PickerDelegate receives picker, recording, and clip-buffer callbacks and forwards them to the manager on the main actor. |
| Main patterns | Published state on one main-actor owner; environment-object injection; delegate objects that hop to the main actor; a checked continuation that turns “recording finished” into an await. |
| Project style | Six Swift files: app entry, ContentView.swift (also holds RecordingPreviewPresenter), CaptureManager.swift, PickerDelegate.swift, and two views under Views/. |
| Execution model | CaptureManager and RecordingPreviewPresenter are @MainActor. Framework delegate methods are nonisolated and re-enter with Task { @MainActor in ... }. Stream sample output is scheduled on .main as its sampleHandlerQueue. |
| State/event model | @Published properties observed through @EnvironmentObject and @StateObject; onChange(of:) on recording and clip URLs triggers the preview. |
| Key frameworks/packages | ScreenCaptureKit (imported with @preconcurrency), AVFoundation, CoreMedia, OSLog, SwiftUI, UIKit. The project declares no Swift package. |
Project structure
iOSSCKSample.xcodeproj/ one iOS application target
iOSSCKSample/
├── iOSSCKSampleApp.swift @main SCKSampleApp -> WindowGroup { ContentView() }
├── ContentView.swift ContentView (creates CaptureManager), RecordingPreviewPresenter
├── CaptureManager.swift @MainActor ObservableObject; SCStream, outputs, picker config
├── PickerDelegate.swift picker / recording / clip-buffer delegate, @unchecked Sendable
├── Views/
│ ├── CapturePickerView.swift capture, record, clip sections; triggers preview
│ └── PickerConfigurationView.swift toggles bound to picker configuration flags
├── Info.plist camera usage, UIBackgroundModes audio + screen-capture
└── iOSSCKSample.entitlements com.apple.developer.screen-recording
Structure observations
- All ScreenCaptureKit stream state is concentrated in
CaptureManager.swift, grouped by// MARK:into published state, picker configuration, stream life cycle, recording, clip buffering, and helpers (iOSSCKSample/CaptureManager.swift:22,iOSSCKSample/CaptureManager.swift:111,iOSSCKSample/CaptureManager.swift:184,iOSSCKSample/CaptureManager.swift:257). - Delegate callbacks for the picker and for recording and clip-buffering outputs live in their own type,
PickerDelegate, whose header comment explains the split: ScreenCaptureKit “calls these delegate methods from background queues, not the main actor” (iOSSCKSample/PickerDelegate.swift:14). RecordingPreviewPresenter, theSCRecordingEditorwrapper, is declared inContentView.swiftbut owned byCapturePickerView(iOSSCKSample/ContentView.swift:26,iOSSCKSample/Views/CapturePickerView.swift:17).- The entitlements file grants
com.apple.developer.screen-recording, andInfo.plistlistsaudioandscreen-capturebackground modes (iOSSCKSample/iOSSCKSample.entitlements:5,iOSSCKSample/Info.plist:34).
Platform boundary
The DocC record lists iOS, iPadOS, and Mac Catalyst. The target sets SDKROOT = iphoneos and TARGETED_DEVICE_FAMILY = "1,2" and has no SUPPORTS_MACCATALYST setting (iOSSCKSample.xcodeproj/project.pbxproj:339, iOSSCKSample.xcodeproj/project.pbxproj:343), so the source shows an iPhone and iPad build only. The README adds that the feature requires a physical device on iOS 27 or later and is not available in Simulator (README.md:19).
Overall architecture
flowchart LR
App["SCKSampleApp"] --> Content["ContentView"]
Content -- "@StateObject + environmentObject" --> Manager["CaptureManager (@MainActor)"]
Content --> PickerView["CapturePickerView"]
PickerView --> Manager
PickerView --> Presenter["RecordingPreviewPresenter"]
Config["PickerConfigurationView"] --> Manager
Manager --> Picker["SCContentSharingPicker.shared"]
Manager --> Stream["SCStream + recording / clip / effect outputs"]
Picker -. "observer callbacks" .-> Delegate["PickerDelegate"]
Stream -. "output delegate callbacks" .-> Delegate
Delegate -- "Task @MainActor" --> Manager
Presenter --> Editor["SCRecordingEditor"]
Reference code
iOSSCKSample/ContentView.swift:12 — ContentView
struct ContentView: View {
@StateObject private var captureManager = CaptureManager()
var body: some View {
CapturePickerView()
.environmentObject(captureManager)
}
}Interpretation
Observed: views talk only to CaptureManager, and the manager is the only type that touches SCStream. Framework callbacks arrive at PickerDelegate or at the manager’s own nonisolated stream-delegate methods and are funneled back into the manager on the main actor. The source comment calls CaptureManager “The app’s central model” (iOSSCKSample/CaptureManager.swift:15).
Inference: the separate PickerDelegate keeps every background-queue entry point out of the main-actor class, so the class’s mutable state is only touched after an explicit hop.
Ownership and state
classDiagram
ContentView *-- CaptureManager : @StateObject private
CapturePickerView o-- CaptureManager : @EnvironmentObject
PickerConfigurationView o-- CaptureManager : @EnvironmentObject
CapturePickerView *-- RecordingPreviewPresenter : @StateObject private
CaptureManager *-- PickerDelegate : private var, created in init
PickerDelegate o-- CaptureManager : private weak
CaptureManager *-- SCStream : private(set) var stream
CaptureManager *-- SCRecordingOutput : private var
CaptureManager *-- SCClipBufferingOutput : private var
CaptureManager *-- SCVideoEffectOutput : private var
RecordingPreviewPresenter *-- SCRecordingEditor : private var editor
Ownership evidence
iOSSCKSample/CaptureManager.swift:18 — CaptureManager private state and init
class CaptureManager: NSObject, ObservableObject {
// ...
private let picker = SCContentSharingPicker.shared
private var pickerDelegate: PickerDelegate?
private(set) var stream: SCStream?
private var recordingOutput: SCRecordingOutput?
private var pendingRecordingURL: URL?
var recordingFinishedContinuation: CheckedContinuation<Void, Error>?
private var clipBufferingOutput: SCClipBufferingOutput?
private var videoEffectOutput: SCVideoEffectOutput?
override init() {
super.init()
pickerDelegate = PickerDelegate(manager: self)
}
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ContentView |
CaptureManager |
Creates it in @StateObject private var and injects it with .environmentObject (iOSSCKSample/ContentView.swift:14, iOSSCKSample/ContentView.swift:18) |
CaptureManager methods; PickerConfigurationView toggles write two flags directly |
CaptureManager |
PickerDelegate |
Creates and retains it; the delegate holds the manager weakly (iOSSCKSample/CaptureManager.swift:58, iOSSCKSample/PickerDelegate.swift:22) |
Set once in init |
CaptureManager |
SCStream |
Created in startCapture(with:), stored after startCapture() succeeds, cleared in tearDownStream() (iOSSCKSample/CaptureManager.swift:130, iOSSCKSample/CaptureManager.swift:145, iOSSCKSample/CaptureManager.swift:163) |
Only CaptureManager (private(set)) |
CaptureManager |
Recording, clip-buffering, and video-effect outputs | Created when the feature starts and added to the stream (iOSSCKSample/CaptureManager.swift:194, iOSSCKSample/CaptureManager.swift:265, iOSSCKSample/CaptureManager.swift:140) |
Only CaptureManager |
CaptureManager |
isCapturing, isRecording, isClipBuffering, lastRecordingURL, lastClipURL, errorMessage, … |
@Published var, implicit internal (iOSSCKSample/CaptureManager.swift:26) |
The manager, plus PickerDelegate error paths (iOSSCKSample/PickerDelegate.swift:74) |
CapturePickerView |
RecordingPreviewPresenter |
@StateObject private var (iOSSCKSample/Views/CapturePickerView.swift:17) |
The presenter |
RecordingPreviewPresenter |
SCRecordingEditor |
Stored while presented and cleared when the editor dismisses (iOSSCKSample/ContentView.swift:35, iOSSCKSample/ContentView.swift:48) |
The presenter, on the main actor |
Observed: the picker is a shared singleton (SCContentSharingPicker.shared), so CaptureManager does not own its lifetime; it adds and removes its delegate and toggles isActive (iOSSCKSample/CaptureManager.swift:106, iOSSCKSample/CaptureManager.swift:180).
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-actor isolation | @MainActor class CaptureManager, @MainActor final class RecordingPreviewPresenter |
All published state and stream bookkeeping are main-actor isolated | iOSSCKSample/CaptureManager.swift:17, iOSSCKSample/ContentView.swift:25 |
| Callback entry points | nonisolated delegate methods on PickerDelegate, on CaptureManager’s SCStreamDelegate extension, and on the editor delegate |
Each method that changes state starts Task { @MainActor in ... } before touching the manager or presenter |
iOSSCKSample/PickerDelegate.swift:39, iOSSCKSample/CaptureManager.swift:344, iOSSCKSample/ContentView.swift:48 |
| Main-queue scheduling | addStreamOutput(self, type: .screen, sampleHandlerQueue: .main) (and .microphone) |
Sample buffers would be delivered on the main queue; the handler is an empty nonisolated method |
iOSSCKSample/CaptureManager.swift:132, iOSSCKSample/CaptureManager.swift:134, iOSSCKSample/CaptureManager.swift:334 |
| Continuation bridge | withCheckedThrowingContinuation stored in recordingFinishedContinuation |
stopRecording() suspends until recordingFinished(output:) or the delegate’s failure path resumes it; both resume paths nil the stored continuation |
iOSSCKSample/CaptureManager.swift:213, iOSSCKSample/CaptureManager.swift:242, iOSSCKSample/PickerDelegate.swift:72 |
| Completion-handler hop | exportClip(to:duration:) { [weak self] error in Task { @MainActor [weak self] in ... } } |
The export completion hops to the main actor to publish lastClipURL or errorMessage |
iOSSCKSample/CaptureManager.swift:294, iOSSCKSample/CaptureManager.swift:295 |
| Nonisolated work | private nonisolated func activateAudioSession() async throws / deactivateAudioSession() |
Called with await from main-actor methods; the source does not establish which executor runs them |
iOSSCKSample/CaptureManager.swift:310, iOSSCKSample/CaptureManager.swift:316 |
| Unretained tasks | showStatus(_:) sleeps three seconds then clears statusMessage; button actions Task { await captureManager.stopCapture() } |
Inherit main-actor context; not stored or cancelled | iOSSCKSample/CaptureManager.swift:251, iOSSCKSample/Views/CapturePickerView.swift:106 |
| Sendability claim | PickerDelegate: ... @unchecked Sendable |
Its only stored state is a weak manager set in init and a let logger; the conformance is unchecked, not compiler-verified |
iOSSCKSample/PickerDelegate.swift:20, iOSSCKSample/PickerDelegate.swift:22 |
| Framework annotations | @preconcurrency import ScreenCaptureKit |
The source comment says this suppresses Sendable diagnostics for ScreenCaptureKit types |
iOSSCKSample/CaptureManager.swift:8, iOSSCKSample/CaptureManager.swift:10 |
Reference code
iOSSCKSample/PickerDelegate.swift:33 — picker callback hops to the main actor
nonisolated func contentSharingPicker(
_ picker: SCContentSharingPicker,
didUpdateWith filter: SCContentFilter,
for stream: SCStream?
) {
logger.debug("Picker didUpdateWith filter (stream: \(stream != nil ? "existing" : "new"))")
Task { @MainActor in
await manager?.startCapture(with: filter)
}
}Interpretation: the main actor is the single synchronization domain for CaptureManager state. The source never protects that state with a lock or queue; correctness depends on every external callback taking the Task { @MainActor } hop, which each state-changing callback does. Not established by source: the specific queues ScreenCaptureKit uses for the picker and output delegates, beyond the header comment.
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 with @Published |
Views re-render from capture flags, URLs, and messages | iOSSCKSample/CaptureManager.swift:18, iOSSCKSample/CaptureManager.swift:26 |
| State propagation | .environmentObject / @EnvironmentObject |
CapturePickerView and the configuration sheet read the same manager |
iOSSCKSample/ContentView.swift:18, iOSSCKSample/Views/CapturePickerView.swift:13, iOSSCKSample/Views/PickerConfigurationView.swift:13 |
| State propagation | $captureManager.showsMicrophoneControl / showsCameraControl bindings |
Toggles write the flags that the computed picker configurations read | iOSSCKSample/Views/PickerConfigurationView.swift:35, iOSSCKSample/CaptureManager.swift:72 |
| Event trigger | onChange(of: captureManager.lastRecordingURL) and lastClipURL |
A new URL makes the view call previewPresenter.preview(url:) |
iOSSCKSample/Views/CapturePickerView.swift:40, iOSSCKSample/Views/CapturePickerView.swift:43 |
| Framework import | @preconcurrency ScreenCaptureKit, AVFoundation, CoreMedia, OSLog |
Stream, outputs, audio session, front camera device, logging | iOSSCKSample/CaptureManager.swift:10, iOSSCKSample/CaptureManager.swift:13 |
| Framework import | SwiftUI, ScreenCaptureKit, UIKit |
Views and the UIWindowScene lookup for SCRecordingEditor |
iOSSCKSample/ContentView.swift:8, iOSSCKSample/ContentView.swift:10 |
| Package declaration | None | The project file declares no Swift package | iOSSCKSample.xcodeproj/project.pbxproj:134 |
Combine scheduling: the source does not import Combine or call receive(on:) / subscribe(on:). @Published is used only through ObservableObject observation.
Class and protocol design
classDiagram
class SCContentSharingPickerObserver {
<<protocol>>
}
class SCRecordingOutputDelegate {
<<protocol>>
}
class SCClipBufferingOutputDelegate {
<<protocol>>
}
class SCStreamDelegate {
<<protocol>>
}
class SCStreamOutput {
<<protocol>>
}
PickerDelegate ..|> SCContentSharingPickerObserver
PickerDelegate ..|> SCRecordingOutputDelegate
PickerDelegate ..|> SCClipBufferingOutputDelegate
CaptureManager ..|> SCStreamDelegate
CaptureManager ..|> SCStreamOutput
RecordingPreviewPresenter ..|> SCRecordingEditorDelegate
PickerDelegate --> CaptureManager : weak, forwards on MainActor
Reference code
iOSSCKSample/PickerDelegate.swift:16 — one delegate object for three framework protocols
class PickerDelegate: NSObject,
SCContentSharingPickerObserver,
SCRecordingOutputDelegate,
SCClipBufferingOutputDelegate,
@unchecked Sendable {
private weak var manager: CaptureManager?
private let logger = Logger()
init(manager: CaptureManager) {
self.manager = manager
}
// ...
}| Type | Responsibility | Depends on |
|---|---|---|
CaptureManager |
Picker configuration and presentation, stream life cycle, recording, clip buffering, audio session, published UI state | SCStream, SCContentSharingPicker, outputs, PickerDelegate |
PickerDelegate |
Receives picker, recording, and clip-buffer callbacks and forwards them on the main actor | CaptureManager (weak) |
RecordingPreviewPresenter |
Presents SCRecordingEditor for a finished file and publishes editor errors |
SCRecordingEditor, UIWindowScene |
CapturePickerView |
Capture, recording, clip sections; starts previews when URLs change | CaptureManager, RecordingPreviewPresenter |
PickerConfigurationView |
Sheet with the two picker-control toggles | CaptureManager |
Observed: the sample declares no protocol of its own; it adopts ScreenCaptureKit delegate protocols. CaptureManager is passed as delegate: self to SCStream and as the stream output (iOSSCKSample/CaptureManager.swift:130), while PickerDelegate is passed to the picker and to SCRecordingOutput / SCClipBufferingOutput (iOSSCKSample/CaptureManager.swift:107, iOSSCKSample/CaptureManager.swift:194, iOSSCKSample/CaptureManager.swift:265).
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
CaptureManager.stream (iOSSCKSample/CaptureManager.swift:49) |
private(set) |
Readable module-wide, assignable only inside CaptureManager |
Inference: the stream’s lifetime is tied to startCapture / tearDownStream. |
picker, pickerDelegate, recordingOutput, pendingRecordingURL, clipBufferingOutput, videoEffectOutput (iOSSCKSample/CaptureManager.swift:47) |
private |
Views cannot reach the picker or outputs directly | Inference: all framework objects stay behind the manager’s methods. |
CaptureManager.recordingFinishedContinuation (iOSSCKSample/CaptureManager.swift:52) |
implicit internal |
PickerDelegate can resume and clear it on failure (iOSSCKSample/PickerDelegate.swift:72) |
Inference: widened from private so the separate delegate type can finish the bridge. |
@Published state (iOSSCKSample/CaptureManager.swift:26) |
implicit internal |
Views and PickerDelegate can write, not only read |
Inference: the delegate’s error paths set errorMessage, isRecording, and isClipBuffering directly. |
setupPicker(), tearDownStream(), showStatus(_:), makeOutputURL(prefix:ext:) (iOSSCKSample/CaptureManager.swift:103, iOSSCKSample/CaptureManager.swift:156) |
private |
Internal steps of the public operations | Inference: callers use the higher-level commands. |
PickerDelegate.manager (iOSSCKSample/PickerDelegate.swift:22) |
private weak |
Only the delegate reads it; it does not retain the manager | Inference: avoids a cycle with the manager’s strong pickerDelegate. |
RecordingPreviewPresenter.editor (iOSSCKSample/ContentView.swift:29) |
private |
Only the presenter keeps the editor alive | Inference: the editor is retained only while presented. |
Reference code
iOSSCKSample/CaptureManager.swift:47 — private framework objects and the widened continuation
private let picker = SCContentSharingPicker.shared
private var pickerDelegate: PickerDelegate?
private(set) var stream: SCStream?
private var recordingOutput: SCRecordingOutput?
private var pendingRecordingURL: URL?
var recordingFinishedContinuation: CheckedContinuation<Void, Error>?All types share one module and none is public or open; undecorated declarations are Swift’s implicit internal.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Picker configuration per mode | CaptureManager.fullDisplayPickerConfiguration / inAppPickerConfiguration |
Computed from published flags; camera control applies only in-app (iOSSCKSample/CaptureManager.swift:64). |
| Restart on new filter | CaptureManager.startCapture(with:) |
Stops recording and buffering, tears down the old stream, optionally activates audio, then builds a new SCStream (iOSSCKSample/CaptureManager.swift:115). |
| Camera video effect | CaptureManager.startCapture(with:) |
Added only for in-app capture with camera enabled; its preview is framework-managed per the source comment (iOSSCKSample/CaptureManager.swift:136). |
| Unexpected stop | CaptureManager.stream(_:didStopWithError:) |
Resets published flags on the main actor (iOSSCKSample/CaptureManager.swift:342). |
| Output file naming | CaptureManager.makeOutputURL(prefix:ext:) |
Time-stamped files in the temporary directory (iOSSCKSample/CaptureManager.swift:321). |
| Preview presentation | RecordingPreviewPresenter.preview(url:) |
Finds the first UIWindowScene and presents SCRecordingEditor; saving happens only if the person chooses Save there (iOSSCKSample/ContentView.swift:31). |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Publisher-backed observable state | @MainActor class CaptureManager: NSObject, ObservableObject with @Published properties (iOSSCKSample/CaptureManager.swift:18, iOSSCKSample/CaptureManager.swift:26) |
Views observe capture state; the published properties are writable module-wide, so mutation is by convention rather than enforced. |
| SwiftUI environment injection | .environmentObject(captureManager) and @EnvironmentObject private var captureManager (iOSSCKSample/ContentView.swift:18, iOSSCKSample/Views/CapturePickerView.swift:13) |
One manager instance reaches the main view and the configuration sheet. |
| Delegate or data-source callbacks | PickerDelegate adopts three ScreenCaptureKit delegate protocols; CaptureManager adopts SCStreamDelegate and SCStreamOutput (iOSSCKSample/PickerDelegate.swift:16, iOSSCKSample/CaptureManager.swift:339) |
Framework events reach the app through delegates that forward on the main actor. |
| Callback-to-async continuation bridge | stopRecording() awaits withCheckedThrowingContinuation, resumed from recordingFinished(output:) or the delegate failure path (iOSSCKSample/CaptureManager.swift:213, iOSSCKSample/CaptureManager.swift:244) |
Lets startCapture and stopCapture wait for the file to finish writing before continuing. |
The type named CaptureManager is described by the patterns above; no separate “Manager” or “Service object” role is claimed from its suffix.
Main application flow
sequenceDiagram
actor User
participant View as CapturePickerView
participant Manager as CaptureManager
participant Stream as SCStream
participant Delegate as PickerDelegate
User->>View: Stop Recording
View->>Manager: Task { await stopRecording() }
Manager->>Manager: store recordingFinishedContinuation
Manager->>Stream: removeRecordingOutput(output)
Stream-->>Delegate: recordingOutputDidFinishRecording
Delegate->>Manager: Task @MainActor recordingFinished(output:)
Manager->>Manager: lastRecordingURL = url, resume continuation
Manager-->>View: onChange(lastRecordingURL) -> preview(url:)
Reference code
iOSSCKSample/CaptureManager.swift:207 — stopRecording() suspends on a continuation
func stopRecording() async {
logger.debug("Recording Stopped")
guard let output = recordingOutput, let stream else { return }
recordingOutput = nil
isRecording = false
do {
try await withCheckedThrowingContinuation { continuation in
recordingFinishedContinuation = continuation
do {
try stream.removeRecordingOutput(output)
} catch {
recordingFinishedContinuation = nil
continuation.resume(throwing: error)
}
}
} catch {
logger.error("Failed to stop recording: \(error)")
errorMessage = error.localizedDescription
}
}iOSSCKSample/PickerDelegate.swift:62 — delegate forwards completion on the main actor
nonisolated func recordingOutputDidFinishRecording(_ recordingOutput: SCRecordingOutput) {
logger.log("Recording finished")
Task { @MainActor in
manager?.recordingFinished(output: recordingOutput)
}
}iOSSCKSample/CaptureManager.swift:232 — publishes the URL and resumes the waiter
func recordingFinished(output: SCRecordingOutput) {
logger.debug("Recording Finished")
finishedRecordingOutput = output
isRecording = false
recordingOutput = nil
if let url = pendingRecordingURL {
pendingRecordingURL = nil
lastRecordingURL = url
showStatus("Recording ready to preview")
}
if let continuation = recordingFinishedContinuation {
recordingFinishedContinuation = nil
continuation.resume()
}
}iOSSCKSample/Views/CapturePickerView.swift:41 — the view reacts to the new URL
.onChange(of: captureManager.lastRecordingURL) { _, url in
if let url { previewPresenter.preview(url: url) }
}Observed: the same recordingFinished(output:) path runs when the stream stops on its own, so the URL is published even without a pending stopRecording() call; the continuation is resumed only if one is stored.
Naming conventions
- Types: role suffixes describe the collaboration:
CaptureManager(stream owner),PickerDelegate(delegate adopter),RecordingPreviewPresenter(presents an editor), and…Viewfor SwiftUI views. The app type isSCKSampleAppwhile its file isiOSSCKSampleApp.swift. - Protocols: none declared locally.
- Methods: paired verbs for each feature (
startCapture/stopCapture,startRecording/stopRecording,startClipBuffering/stopClipBuffering),present…Pickerfor the two modes,tearDownStreamfor cleanup, and past-tenserecordingFinished(output:)for the callback-driven handler. Booleans useis…andshows…(isCapturing,showsCameraControl). - Files and extensions: one primary type per file, except
ContentView.swift, which also holdsRecordingPreviewPresenter. Protocol conformances ofCaptureManagerare in// MARK:-labeled extensions at the end of its file.
Architecture takeaways
- One main-actor owner holds every framework object and every piece of UI-visible state; all framework callbacks hop onto the main actor before touching it.
- Moving delegate conformances into a separate
nonisolated, weakly-referencing object (PickerDelegate) keeps background entry points out of the main-actor class and avoids a retain cycle. - A stored
CheckedContinuationturns “recording finished writing” into an awaitable step, which lets restart and stop flows wait for file completion. - Publishing the result URL and reacting with
onChangekeeps presentation (SCRecordingEditor) in the view layer while the manager stays UI-free. - Widening
recordingFinishedContinuationand the published flags tointernalis the cost of splitting the delegate into its own type.
Source map
| Source file | Relevant symbols |
|---|---|
iOSSCKSample/iOSSCKSampleApp.swift |
SCKSampleApp |
iOSSCKSample/ContentView.swift |
ContentView, RecordingPreviewPresenter, preview(url:), SCRecordingEditorDelegate |
iOSSCKSample/CaptureManager.swift |
CaptureManager, CaptureMode, presentFullDisplayPicker(), presentInAppPicker(), startCapture(with:), tearDownStream(), stopCapture(), startRecording(), stopRecording(), recordingFinished(output:), startClipBuffering(), exportCurrentClip(duration:), SCStreamOutput, SCStreamDelegate |
iOSSCKSample/PickerDelegate.swift |
PickerDelegate, contentSharingPicker(_:didUpdateWith:for:), recordingOutputDidFinishRecording(_:), recordingOutput(_:didFailWithError:) |
iOSSCKSample/Views/CapturePickerView.swift |
CapturePickerView, previewPresenter, stopSection |
iOSSCKSample/Views/PickerConfigurationView.swift |
PickerConfigurationView, sharedOptionsSection |
iOSSCKSample/Info.plist |
NSCameraUsageDescription, UIBackgroundModes |
iOSSCKSample/iOSSCKSample.entitlements |
com.apple.developer.screen-recording |
iOSSCKSample.xcodeproj/project.pbxproj |
SDKROOT, TARGETED_DEVICE_FAMILY, IPHONEOS_DEPLOYMENT_TARGET, SWIFT_VERSION |
README.md |
Device and OS requirement |