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

Updating an app to use strict concurrency

At a glance

Item Summary
Purpose Use this code to follow along with a guide to migrating your code to take advantage of the full concurrency protection that the Swift 6 language mode provides.
App architecture A Swift sample bundle with entry-bearing project variants Original, Updated, each leading to SwiftUI APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Central store, SwiftUI environment injection, Publisher-backed observable state
Project style 22 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── Original/
│   └── Coffee Tracker WatchKit Extension/
│       ├── CoffeeTrackerApp.swift
│       ├── ExtensionDelegate.swift
│       ├── ContentView.swift
│       ├── CoffeeTrackerView.swift
│       ├── DrinkListView.swift
│       ├── ComplicationController.swift
│       └── HostingController.swift
└── Updated/
    └── Coffee Tracker WatchKit Extension/
        ├── CoffeeTrackerApp.swift
        ├── ExtensionDelegate.swift
        ├── ContentView.swift
        ├── CoffeeTrackerView.swift
        └── DrinkListView.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 11 project/configuration file(s) and 29 source declaration(s).

Overall architecture

Reference code

Original/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift:10 — architecture anchor

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

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

Original/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift:13 — stored dependency or nearest verified ownership anchor

@main
struct CoffeeTrackerApp: App {
    // ...
    @WKApplicationDelegateAdaptor private var appDelegate: ExtensionDelegate
    // ...
}
Owner Object or state Relationship Mutation authority
CoffeeTrackerApp ExtensionDelegate (appDelegate) stores or receives Owning lexical scope
ExtensionDelegate Logger (logger) creates and retains Initialized by the owner; the binding is immutable
ExtensionDelegate Logger (scheduleLogger) creates and retains Initialized by the owner; the binding is immutable
ContentView Logger (logger) creates and retains 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

Updated/CoffeeKit/CoffeeData.swift:310 — representative type boundary

public protocol CaffeineThresholdDelegate: AnyObject {
    func caffeineLevel(at level: Double)
}
Type Responsibility Depends on or conforms to
CoffeeTrackerApp Application entry and top-level composition App
CoffeeTrackerApp Application entry and top-level composition App
CaffeineThresholdDelegate Defines a capability or collaboration contract AnyObject
CaffeineThresholdDelegate Defines a capability or collaboration contract AnyObject
ExtensionDelegate Receives callback-driven events NSObject, WKApplicationDelegate
ExtensionDelegate Receives callback-driven events NSObject, WKApplicationDelegate
ContentView User-interface presentation and input forwarding View
ContentView User-interface presentation and input forwarding View
CoffeeTrackerView User-interface presentation and input forwarding View
DrinkListView User-interface presentation and input forwarding View

The source explicitly defines local protocol relationships: RecaffeinaterCaffeineThresholdDelegate, RecaffeinaterCaffeineThresholdDelegate.

Access control

Symbol Access Verified effect Likely rationale
appDelegate (Original/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift:13) 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.
colorForCaffeineDose (Original/Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift:53) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.
colorForDailyDrinkCount (Original/Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift:60) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.
createTimelineEntry (Original/Coffee Tracker WatchKit Extension/ComplicationController.swift:98) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.

Reference code

Original/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift:13 — representative boundary

@main
struct CoffeeTrackerApp: App {
    // ...
    @WKApplicationDelegateAdaptor private var appDelegate: ExtensionDelegate
    // ...
}

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 CoffeeTrackerApp The source’s App suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination ComplicationController, HealthKitController, HostingController The source’s Controller suffix makes this role explicit.
Receives callback-driven events CaffeineThresholdDelegate, CoffeeLocationDelegate, ExtensionDelegate The source’s Delegate suffix makes this role explicit.
Centralized state or persistence access CoffeeDataStore The source’s Store suffix makes this role explicit.
User-interface presentation and input forwarding CoffeeTrackerView, ContentView, DrinkListView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Original/Coffee Tracker WatchKit Extension/ComplicationController.swift:11 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction Original/Coffee Tracker WatchKit Extension/ContentView.swift:74 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks Original/Coffee Tracker WatchKit Extension/ComplicationController.swift:11 Callback protocols invert event delivery back into the sample’s owner.
Central store Original/CoffeeKit/CoffeeData.swift:15 A store-named type centralizes feature state or persistence.
SwiftUI environment injection Original/Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift:14 The environment supplies state or a capability without threading it through every initializer.
Publisher-backed observable state Original/Coffee Tracker WatchKit Extension/ContentView.swift:70 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: CoffeeTrackerApp; Controller: ComplicationController, HealthKitController, HostingController; Delegate: CaffeineThresholdDelegate, CoffeeLocationDelegate, ExtensionDelegate; Store: CoffeeDataStore; View: CoffeeTrackerView, ContentView, DrinkListView.
  • Protocols: CaffeineThresholdDelegate, CaffeineThresholdDelegate.
  • Methods: handle, scheduleBackgroundRefreshTasks, caffeineLevel, colorForCaffeineDose, colorForDailyDrinkCount, addDrink.
  • Files: Original/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift, Updated/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift, Original/Coffee Tracker WatchKit Extension/ExtensionDelegate.swift, Updated/Coffee Tracker WatchKit Extension/ExtensionDelegate.swift, Original/Coffee Tracker WatchKit Extension/ContentView.swift, Updated/Coffee Tracker WatchKit Extension/ContentView.swift.

Architecture takeaways

  • CoffeeTrackerApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, CoffeeKit, ClockKit, HealthKit 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.
  • Local protocol relationships provide an explicit substitution boundary.

Source map

Source file Relevant symbols
Original/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift CoffeeTrackerApp
Updated/Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift CoffeeTrackerApp
Original/Coffee Tracker WatchKit Extension/ExtensionDelegate.swift ExtensionDelegate
Updated/Coffee Tracker WatchKit Extension/ExtensionDelegate.swift ExtensionDelegate
Original/Coffee Tracker WatchKit Extension/ContentView.swift ContentView, Recaffeinater, ContentView_Previews
Updated/Coffee Tracker WatchKit Extension/ContentView.swift ContentView, Recaffeinater, ContentView_Previews
Original/Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift CoffeeTrackerView, CoffeeTrackerView_Previews
Original/Coffee Tracker WatchKit Extension/DrinkListView.swift DrinkListView, DrinkListView_Previews
Updated/Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift CoffeeTrackerView, CoffeeTrackerView_Previews
Updated/Coffee Tracker WatchKit Extension/DrinkListView.swift DrinkListView, DrinkListView_Previews