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. |
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
flowchart LR
N1["ComplicationController"]
N2["ClockKit APIs"]
N1 --> N2
Reference code
Complications WatchKit Extension/ComplicationController.swift:11 — architecture anchor
class ComplicationController: NSObject, CLKComplicationDataSource {
// ...
}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
classDiagram
ContentView o-- TemplateConfiguration : configuration
ContentView o-- Isconfiguratondirty : isConfiguratonDirty
FamilyRowView *-- String : familyName
VariantListView o-- TemplateConfiguration : configuration
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.
Class and protocol design
Complications WatchKit Extension/ContentView.swift:11 — representative type boundary
struct ContentView: View {
// ...
}| 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] {
// ...
}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
ComplicationControlleris 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/ContentView.swift |
ContentView, FamilyRowView, ContentView_Previews |
Complications WatchKit Extension/TemplateConfiguration.swift |
GraphicCornerVariant, GraphicCircularVariant, GraphicRectangleVariant, TemplateConfiguration, CodingKeys |
Complications WatchKit Extension/VariantListView.swift |
VariantListView, VariantListView_Previews |
Complications WatchKit Extension/ComplicationController.swift |
ComplicationController |
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/GraphicCircular.swift |
Feature implementation |
Complications WatchKit Extension/GraphicCorner.swift |
Feature implementation |