Sample CodeiOS, iPadOS, Mac Catalyst, macOS, tvOS, visionOSReviewed 2026-07-21View on Apple Developer

Downloading essential assets in the background

At a glance

Item Summary
Purpose Fetch the assets your app requires before its first launch using an app extension and the Background Assets framework.
App architecture A Swift sample with the source-visible chain AppContentViewPreviewSessionManagerLocalSessionBackgroundAssets APIs.
Main patterns Delegate or data-source callbacks, SwiftUI environment injection, Binding-based state propagation, Publisher-backed observable state, Actor-isolated state
Project style 16 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── WWDC Sessions/
    ├── WWDC Sessions/
    │   ├── App.swift
    │   ├── ContentView.swift
    │   ├── Views/
    │   │   ├── DetailView.swift
    │   │   ├── SessionDescription.swift
    │   │   ├── Thumbnail.swift
    │   │   └── VideoSelectorSidebar.swift
    │   ├── Preview Content/
    │   │   └── PreviewSessionManager.swift
    │   └── Session/
    │       └── SessionManager.swift
    ├── WWDC Sessions Background Assets Extension/
    │   └── BackgroundDownloadHandler.swift
    └── Shared/
        ├── Session/
        │   ├── LocalSession.swift
        │   └── Session.swift
        └── SharedSettings.swift

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 8 project/configuration file(s) and 23 source declaration(s).

Overall architecture

Reference code

WWDC Sessions/WWDC Sessions/App.swift:15 — architecture anchor

@main
struct WWDCSessionsApp: App {
    // ...
}

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 Background Assets.

Ownership and state

Ownership evidence

WWDC Sessions/WWDC Sessions/App.swift:12 — stored dependency or nearest verified ownership anchor

    static let app = Logger(subsystem: "com.example.apple-samplecode.WWDC-Sessions", category: "app")
Owner Object or state Relationship Mutation authority
App Logger (app) creates and retains Initialized by the owner; the binding is immutable
WWDCSessionsApp SessionManager (sessionManager) owns wrapper-managed state Owning lexical scope
BackgroundDownloadHandler Logger (ext) creates and retains Initialized by the owner; the binding is immutable
LocalSession UUID (id) 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.

Class and protocol design

WWDC Sessions/WWDC Sessions/App.swift:16 — representative type boundary

struct WWDCSessionsApp: App {
    // ...
}
Type Responsibility Depends on or conforms to
WWDCSessionsApp Application entry and top-level composition App
BackgroundDownloadHandler Handles callbacks or feature events BADownloaderExtension
LocalSession Owns a session-scoped interaction Session, ObservableObject, Identifiable, @unchecked Sendable
Session Owns a session-scoped interaction Codable
ContentView User-interface presentation and input forwarding View
DetailView User-interface presentation and input forwarding View
PreviewSessionManager Long-lived feature or framework coordination ObservableObject
SessionManager Long-lived feature or framework coordination NSObject, ObservableObject, @unchecked Sendable
State Represents mutable feature state Decodable
ImageGenerationError Represents feature failure conditions Error

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
sessions (WWDC Sessions/Shared/Manifest.swift:11) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
sessionsByDownloadIdentifier (WWDC Sessions/Shared/Manifest.swift:12) 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.
stateLock (WWDC Sessions/Shared/Session/LocalSession.swift:57) 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.
fileURL (WWDC Sessions/Shared/Session/LocalSession.swift:117) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.

Reference code

WWDC Sessions/Shared/Manifest.swift:11 — representative boundary

    public let sessions: [LocalSession]

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 WWDCSessionsApp The source’s App suffix makes this role explicit.
Handles callbacks or feature events BackgroundDownloadHandler The source’s Handler suffix makes this role explicit.
Long-lived feature or framework coordination PreviewSessionManager, SessionManager The source’s Manager suffix makes this role explicit.
Owns a session-scoped interaction LocalSession, Session The source’s Session suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, DetailView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks WWDC Sessions/WWDC Sessions/Session/SessionManager.swift:165 Callback protocols invert event delivery back into the sample’s owner.
SwiftUI environment injection WWDC Sessions/WWDC Sessions/Views/VideoSelectorSidebar.swift:11 The environment supplies state or a capability without threading it through every initializer.
Binding-based state propagation WWDC Sessions/WWDC Sessions/Views/DetailView.swift:13 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Publisher-backed observable state WWDC Sessions/WWDC Sessions/Preview Content/PreviewSessionManager.swift:12 Published properties notify observers while mutation remains with the state object.
Actor-isolated state WWDC Sessions/Shared/Session/LocalSession.swift:88 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: App: WWDCSessionsApp; Handler: BackgroundDownloadHandler; Manager: PreviewSessionManager, SessionManager; Session: LocalSession, Session; View: ContentView, DetailView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: downloads, backgroundDownload, fetchThumbnail, generateThumbnail, fileURL, hash, handleSelectionsChanged, playCurrentSelection.
  • Files: WWDC Sessions/WWDC Sessions Background Assets Extension/BackgroundDownloadHandler.swift, WWDC Sessions/Shared/Session/LocalSession.swift, WWDC Sessions/Shared/Session/Session.swift, WWDC Sessions/WWDC Sessions/ContentView.swift, WWDC Sessions/WWDC Sessions/Views/DetailView.swift, WWDC Sessions/WWDC Sessions/Preview Content/PreviewSessionManager.swift.

Architecture takeaways

  • App is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, AVKit, BackgroundAssets, 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
WWDC Sessions/WWDC Sessions/App.swift WWDCSessionsApp
WWDC Sessions/WWDC Sessions Background Assets Extension/BackgroundDownloadHandler.swift BackgroundDownloadHandler
WWDC Sessions/Shared/Session/LocalSession.swift LocalSession, State, ImageGenerationError, CodingKeys
WWDC Sessions/Shared/Session/Session.swift WWDC, Year, Session
WWDC Sessions/WWDC Sessions/ContentView.swift ContentView, ContentView_Previews
WWDC Sessions/WWDC Sessions/Views/DetailView.swift DetailView, DetailView_Previews
WWDC Sessions/WWDC Sessions/Preview Content/PreviewSessionManager.swift PreviewSessionManager
WWDC Sessions/WWDC Sessions/Session/SessionManager.swift SessionManager
WWDC Sessions/Shared/SharedSettings.swift SharedSettings
WWDC Sessions/WWDC Sessions/Views/SessionDescription.swift SessionDescription, Style, SessionDescription_Previews