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

Displaying essential information on a watch face

At a glance

Item Summary
Purpose Implement complications in a watch app to display essential information on a watch face.
App architecture A Swift sample centered on ComplicationController, with direct use of ClockKit, SwiftUI, WatchKit, UIKit.
Main patterns View-controller organization, Delegate or data-source callbacks, SwiftUI environment injection, Binding-based state propagation
Project style 12 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model No structured execution marker indexed; callback threading requires source review.
State/event model Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published.
Key frameworks/packages ClockKit, SwiftUI, WatchKit, Foundation, Combine; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── Complications WatchKit Extension/
    ├── ContentView.swift
    ├── TemplateConfiguration.swift
    ├── VariantListView.swift
    ├── ComplicationController.swift
    ├── ExtensionDelegate.swift
    ├── HostingController.swift
    ├── Timeline.swift
    ├── GraphicBezel.swift
    ├── GraphicCircular.swift
    ├── GraphicCorner.swift
    ├── GraphicRectangle.swift
    └── Utilities.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 6 project/configuration file(s) and 12 source declaration(s).

Overall architecture

Reference code

Complications WatchKit Extension/ComplicationController.swift:11 — architecture anchor

class ComplicationController: NSObject, CLKComplicationDataSource {
    // ...
    func getSupportedTimeTravelDirections(for complication: CLKComplication,
                                          withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
        handler([.forward])
    }
    // ...
}

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

Ownership and state

Ownership evidence

Complications WatchKit Extension/ContentView.swift:12 — stored dependency or nearest verified ownership anchor

struct ContentView: View {
    @EnvironmentObject var configuration: TemplateConfiguration
    // ...
}
Owner Object or state Relationship Mutation authority
ContentView TemplateConfiguration (configuration) receives environment-provided state The environment provider is authoritative
ContentView Isconfiguratondirty (isConfiguratonDirty) stores or receives App/module collaborators
FamilyRowView String (familyName) owns value state Initialized by the owner; the binding is immutable
VariantListView TemplateConfiguration (configuration) receives environment-provided state The environment provider is authoritative

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.

No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.

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

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 SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. Complications WatchKit Extension/ContentView.swift:12
State propagation ObservableObject ObservableObject supplies an observation contract. Complications WatchKit Extension/TemplateConfiguration.swift:35
State propagation @Published A published property can emit owner-controlled changes. Complications WatchKit Extension/TemplateConfiguration.swift:36
Source import ClockKit The cited file imports this module; runtime use and architectural role are not inferred. Complications WatchKit Extension/ComplicationController.swift:9
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. Complications WatchKit Extension/ContentView.swift:8
Source import WatchKit The cited file imports this module; runtime use and architectural role are not inferred. Complications WatchKit Extension/ComplicationController.swift:8
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Complications WatchKit Extension/GraphicCorner.swift:8
Source import Combine The cited file imports this module; runtime use and architectural role are not inferred. Complications WatchKit Extension/TemplateConfiguration.swift:8

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

Complications WatchKit Extension/ContentView.swift:11 — representative type boundary

struct ContentView: View {
    @EnvironmentObject var configuration: TemplateConfiguration
    // ...
}
Type Responsibility Depends on or conforms to
ContentView User-interface presentation and input forwarding View
FamilyRowView User-interface presentation and input forwarding View
VariantListView User-interface presentation and input forwarding View
ComplicationController View lifecycle, callbacks, and feature coordination NSObject, CLKComplicationDataSource
ExtensionDelegate Receives callback-driven events NSObject, WKExtensionDelegate
HostingController View lifecycle, callbacks, and feature coordination WKHostingController
GraphicCornerVariant Defines a closed set of feature states or choices String, Codable, CaseIterable
GraphicCircularVariant Defines a closed set of feature states or choices String, Codable, CaseIterable
GraphicRectangleVariant Defines a closed set of feature states or choices String, Codable, CaseIterable
TemplateConfiguration Carries feature or framework configuration Codable, ObservableObject, Equatable

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
nextDayEntries (Complications WatchKit Extension/ComplicationController.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.
refreshComplications (Complications WatchKit Extension/ContentView.swift:43) 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.
isConfigurationDirty (Complications WatchKit Extension/ContentView.swift:57) 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.
newGraphicCircularImage (Complications WatchKit Extension/GraphicCircular.swift:36) 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

Complications WatchKit Extension/ComplicationController.swift:60 — representative boundary

    private func nextDayEntries(for complication: CLKComplication, after date: Date, limit: Int) -> [CLKComplicationTimelineEntry] {
        let delegate: ExtensionDelegate! = WKExtension.shared().delegate as? 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
View lifecycle, callbacks, and feature coordination ComplicationController, HostingController The source’s Controller suffix makes this role explicit.
Receives callback-driven events ExtensionDelegate The source’s Delegate suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, FamilyRowView, VariantListView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Complications WatchKit Extension/ComplicationController.swift:11 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Delegate or data-source callbacks Complications WatchKit Extension/ComplicationController.swift:11 Callback protocols invert event delivery back into the sample’s owner.
SwiftUI environment injection Complications WatchKit Extension/ContentView.swift:12 The environment supplies state or a capability without threading it through every initializer.
Binding-based state propagation Complications WatchKit Extension/VariantListView.swift:17 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: Controller: ComplicationController, HostingController; Delegate: ExtensionDelegate; View: ContentView, FamilyRowView, VariantListView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: refreshComplications, isConfigurationDirty, encode, save, getSupportedTimeTravelDirections, getTimelineEndDate, getPrivacyBehavior, getCurrentTimelineEntry.
  • Files: Complications WatchKit Extension/ContentView.swift, Complications WatchKit Extension/TemplateConfiguration.swift, Complications WatchKit Extension/VariantListView.swift, Complications WatchKit Extension/ComplicationController.swift, Complications WatchKit Extension/ExtensionDelegate.swift, Complications WatchKit Extension/HostingController.swift.

Architecture takeaways

  • ComplicationController is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches ClockKit, SwiftUI, WatchKit, UIKit 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
Complications WatchKit Extension/ComplicationController.swift ComplicationController, Cited implementation, ClockKit, WatchKit
Complications WatchKit Extension/ContentView.swift Cited implementation, ContentView, SwiftUI state property wrapper, SwiftUI, FamilyRowView, ContentView_Previews
Complications WatchKit Extension/GraphicCircular.swift Cited implementation, Feature implementation
Complications WatchKit Extension/VariantListView.swift Cited implementation, VariantListView, VariantListView_Previews
Complications WatchKit Extension/TemplateConfiguration.swift ObservableObject, @Published, Combine, GraphicCornerVariant, GraphicCircularVariant, GraphicRectangleVariant, TemplateConfiguration, CodingKeys
Complications WatchKit Extension/GraphicCorner.swift Foundation, Feature implementation
Complications WatchKit Extension/ExtensionDelegate.swift ExtensionDelegate
Complications WatchKit Extension/HostingController.swift HostingController
Complications WatchKit Extension/Timeline.swift func, Event, Timeline
Complications WatchKit Extension/GraphicBezel.swift Feature implementation
Complications WatchKit Extension/GraphicRectangle.swift Feature implementation
Complications WatchKit Extension/Utilities.swift Feature implementation