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
Project style 6 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: @MainActor, async declaration or closure, Task, Task closure isolated to MainActor, Sendable or @Sendable; none alone proves a background thread.
State/event model Source-visible mechanisms: ObservableObject, @Published, SwiftUI state property wrapper.
Key frameworks/packages ScreenCaptureKit, SwiftUI, OSLog, AVFoundation, CoreMedia; these are source dependencies, not architecture labels.

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

@MainActor
class CaptureManager: NSObject, ObservableObject {
    // ...
    private let logger = Logger()
    // ...
}
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.

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. iOSSCKSample/CaptureManager.swift:17
Suspension boundary async declaration or closure The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. iOSSCKSample/CaptureManager.swift:115
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. iOSSCKSample/CaptureManager.swift:251
Main isolation Task closure isolated to MainActor The cited operation explicitly enters a main-actor-isolated region. iOSSCKSample/CaptureManager.swift:295
Transfer contract Sendable or @Sendable The source declares a sendability boundary; this alone does not synchronize mutable state. iOSSCKSample/PickerDelegate.swift:20

@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

iOSSCKSample/CaptureManager.swift:17 — representative execution boundary

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

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. iOSSCKSample/CaptureManager.swift:18
State propagation @Published A published property can emit owner-controlled changes. iOSSCKSample/CaptureManager.swift:26
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. iOSSCKSample/ContentView.swift:14
Source import ScreenCaptureKit The cited file imports this module; runtime use and architectural role are not inferred. iOSSCKSample/CaptureManager.swift:10
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. iOSSCKSample/ContentView.swift:8
Source import OSLog The cited file imports this module; runtime use and architectural role are not inferred. iOSSCKSample/CaptureManager.swift:13
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. iOSSCKSample/CaptureManager.swift:11
Source import CoreMedia The cited file imports this module; runtime use and architectural role are not inferred. iOSSCKSample/CaptureManager.swift:12

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

iOSSCKSample/iOSSCKSampleApp.swift:11 — representative type boundary

@main
struct SCKSampleApp: App {
    // ...
            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.

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 Cited implementation, SCKSampleApp
iOSSCKSample/CaptureManager.swift Cited implementation, @MainActor, async declaration or closure, Task, Task closure isolated to MainActor, ObservableObject, @Published, ScreenCaptureKit, OSLog, AVFoundation, CoreMedia, CaptureManager, CaptureMode
iOSSCKSample/Views/CapturePickerView.swift Cited implementation, CapturePickerView
iOSSCKSample/PickerDelegate.swift Sendable or @Sendable, PickerDelegate
iOSSCKSample/ContentView.swift SwiftUI state property wrapper, SwiftUI, ContentView, RecordingPreviewPresenter
iOSSCKSample/Views/PickerConfigurationView.swift PickerConfigurationView