Sample CodeiOS, iPadOS, Mac CatalystReviewed 2026-07-21View on Apple Developer

Capturing screen content on iOS

At a glance

Item Summary
Purpose Record and share screen captures on iOS by presenting the system content-sharing picker.
App architecture A Swift sample with the source-visible chain iOSSCKSampleAppContentViewCaptureManagerScreenCaptureKit APIs.
Main patterns Delegate or data-source callbacks, SwiftUI environment injection, Publisher-backed observable state, Actor-isolated state
Project style 6 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── iOSSCKSample/
│   ├── iOSSCKSampleApp.swift
│   ├── CaptureManager.swift
│   ├── Views/
│   │   ├── CapturePickerView.swift
│   │   └── PickerConfigurationView.swift
│   ├── ContentView.swift
│   ├── PickerDelegate.swift
│   ├── Info.plist
│   └── iOSSCKSample.entitlements
├── Configuration/
│   └── SampleCode.xcconfig
└── iOSSCKSample.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 5 project/configuration file(s) and 8 source declaration(s).

Overall architecture

Reference code

iOSSCKSample/iOSSCKSampleApp.swift:10 — architecture anchor

@main
struct SCKSampleApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

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 ScreenCaptureKit.

Ownership and state

Ownership evidence

iOSSCKSample/CaptureManager.swift:20 — stored dependency or nearest verified ownership anchor

    private let logger = Logger()

    // MARK: - Published State

    // These properties mirror the state of the active stream and its outputs. SwiftUI views
    // read them directly through the `@EnvironmentObject` to drive their controls.
    @Published var isCapturing = false
Owner Object or state Relationship Mutation authority
CaptureManager Logger (logger) creates and retains Initialized by the owner; the binding is immutable
CaptureManager SCRecordingOutput (finishedRecordingOutput) stores or receives App/module collaborators
CaptureManager URL (lastRecordingURL) owns value state App/module collaborators
CaptureManager URL (lastClipURL) owns value state App/module collaborators

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.

Class and protocol design

iOSSCKSample/iOSSCKSampleApp.swift:11 — representative type boundary

struct SCKSampleApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
Type Responsibility Depends on or conforms to
SCKSampleApp Application entry and top-level composition App
CaptureManager Long-lived feature or framework coordination NSObject, ObservableObject
CapturePickerView User-interface presentation and input forwarding View
ContentView User-interface presentation and input forwarding View
PickerDelegate Receives callback-driven events NSObject
PickerConfigurationView User-interface presentation and input forwarding View
CaptureMode Defines a closed set of feature states or choices Concrete collaborators/imported frameworks
RecordingPreviewPresenter Owns feature behavior and collaborator lifecycle NSObject, ObservableObject

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 (iOSSCKSample/CaptureManager.swift:20) 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.
picker (iOSSCKSample/CaptureManager.swift:47) 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.
pickerDelegate (iOSSCKSample/CaptureManager.swift:48) 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.
stream (iOSSCKSample/CaptureManager.swift:49) 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

iOSSCKSample/CaptureManager.swift:20 — representative boundary

@MainActor
class CaptureManager: NSObject, ObservableObject {
    // ...
    private let logger = Logger()
    // ...
}

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 SCKSampleApp The source’s App suffix makes this role explicit.
Receives callback-driven events PickerDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination CaptureManager The source’s Manager suffix makes this role explicit.
User-interface presentation and input forwarding CapturePickerView, ContentView, PickerConfigurationView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks iOSSCKSample/CaptureManager.swift:339 Callback protocols invert event delivery back into the sample’s owner.
SwiftUI environment injection iOSSCKSample/Views/CapturePickerView.swift:13 The environment supplies state or a capability without threading it through every initializer.
Publisher-backed observable state iOSSCKSample/CaptureManager.swift:29 Published properties notify observers while mutation remains with the state object.
Actor-isolated state iOSSCKSample/CaptureManager.swift:17 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: App: SCKSampleApp; Delegate: PickerDelegate; Manager: CaptureManager; View: CapturePickerView, ContentView, PickerConfigurationView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: presentFullDisplayPicker, presentInAppPicker, setupPicker, startCapture, tearDownStream, stopCapture, startRecording, stopRecording.
  • Files: iOSSCKSample/CaptureManager.swift, iOSSCKSample/Views/CapturePickerView.swift, iOSSCKSample/ContentView.swift, iOSSCKSample/PickerDelegate.swift, iOSSCKSample/Views/PickerConfigurationView.swift.

Architecture takeaways

  • iOSSCKSampleApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches ScreenCaptureKit, SwiftUI, AVFoundation, CoreMedia 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
iOSSCKSample/iOSSCKSampleApp.swift SCKSampleApp
iOSSCKSample/CaptureManager.swift CaptureManager, CaptureMode
iOSSCKSample/Views/CapturePickerView.swift CapturePickerView
iOSSCKSample/ContentView.swift ContentView, RecordingPreviewPresenter
iOSSCKSample/PickerDelegate.swift PickerDelegate
iOSSCKSample/Views/PickerConfigurationView.swift PickerConfigurationView