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
Project style 16 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: Sendable or @Sendable, NSLock, Task, await suspension point, @MainActor; none alone proves a background thread.
State/event model Source-visible mechanisms: ObservableObject, @Published, SwiftUI state property wrapper.
Key frameworks/packages SwiftUI, Foundation, OSLog, AVKit, BackgroundAssets; these are source dependencies, not architecture labels.

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 {
    @StateObject private var sessionManager = SessionManager()

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(self.sessionManager)
        }
        #if os(macOS)
        .defaultSize(width: 900, height: 750)
        #endif
    }
}

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

public extension Logger {
    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.

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
Transfer contract Sendable or @Sendable The source declares a sendability boundary; this alone does not synchronize mutable state. WWDC Sessions/Shared/Session/LocalSession.swift:13
Synchronization NSLock The source references a synchronization primitive; the protected state requires surrounding review. WWDC Sessions/Shared/Session/LocalSession.swift:57
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. WWDC Sessions/Shared/Session/LocalSession.swift:82
Suspension boundary await suspension point The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. WWDC Sessions/Shared/Session/LocalSession.swift:83
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. WWDC Sessions/Shared/Session/LocalSession.swift:88

@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

WWDC Sessions/Shared/Session/LocalSession.swift:13 — representative execution boundary

final class LocalSession: Session, ObservableObject, Identifiable, @unchecked Sendable {
    // ...
        case downloaded
    // ...
}

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. WWDC Sessions/Shared/Session/LocalSession.swift:13
State propagation @Published A published property can emit owner-controlled changes. WWDC Sessions/Shared/Session/LocalSession.swift:27
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. WWDC Sessions/WWDC Sessions/App.swift:17
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. WWDC Sessions/Shared/Session/LocalSession.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. WWDC Sessions/Shared/Manifest.swift:8
Source import OSLog The cited file imports this module; runtime use and architectural role are not inferred. WWDC Sessions/Shared/Session/LocalSession.swift:11
Source import AVKit The cited file imports this module; runtime use and architectural role are not inferred. WWDC Sessions/WWDC Sessions/Views/DetailView.swift:10
Source import BackgroundAssets The cited file imports this module; runtime use and architectural role are not inferred. WWDC Sessions/WWDC Sessions Background Assets Extension/BackgroundDownloadHandler.swift:7

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

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

@main
struct WWDCSessionsApp: App {
    @StateObject private var sessionManager = SessionManager()
    // ...
}
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

final class Manifest: Codable {
    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.

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 Cited implementation, WWDCSessionsApp, SwiftUI state property wrapper
WWDC Sessions/Shared/Manifest.swift Cited implementation, Foundation, Manifest, CodingKeys
WWDC Sessions/Shared/Session/LocalSession.swift Cited implementation, Sendable or @Sendable, NSLock, Task, await suspension point, @MainActor, ObservableObject, @Published, SwiftUI, OSLog, LocalSession, State, ImageGenerationError, CodingKeys
WWDC Sessions/WWDC Sessions/Session/SessionManager.swift Cited implementation, SessionManager
WWDC Sessions/WWDC Sessions/Views/VideoSelectorSidebar.swift Cited implementation, VideoSelectorSidebar, VideoSelectorSidebar_Previews, Preview
WWDC Sessions/WWDC Sessions/Views/DetailView.swift Cited implementation, AVKit, DetailView, DetailView_Previews
WWDC Sessions/WWDC Sessions/Preview Content/PreviewSessionManager.swift Cited implementation, PreviewSessionManager
WWDC Sessions/WWDC Sessions Background Assets Extension/BackgroundDownloadHandler.swift BackgroundAssets, BackgroundDownloadHandler
WWDC Sessions/Shared/Session/Session.swift WWDC, Year, Session
WWDC Sessions/WWDC Sessions/ContentView.swift ContentView, ContentView_Previews
WWDC Sessions/Shared/SharedSettings.swift SharedSettings
WWDC Sessions/WWDC Sessions/Views/SessionDescription.swift SessionDescription, Style, SessionDescription_Previews
WWDC Sessions/WWDC Sessions/Views/Thumbnail.swift Thumbnail, GaugeProgressStyle, Thumbnail_Previews
WWDC Sessions/WWDC Sessions/Views/VideoSelector.swift VideoSelector, VideoSelector_Previews
WWDC Sessions/WWDC Sessions/Views/tvOS/Gallery.swift Gallery
WWDC Sessions/WWDC Sessions/Views/tvOS/SessionPage.swift SessionPage