Providing Multiple Complications
At a glance
| Item | Summary |
|---|---|
| Purpose | Present multiple complications for a single complication family using descriptors. |
| App architecture | A Swift sample with the source-visible chain CoffeeTrackerApp → ContentView → ClockKit APIs. |
| Main patterns | View-controller organization, Delegate or data-source callbacks, SwiftUI environment injection |
| Project style | 9 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── Coffee Tracker WatchKit Extension/
│ ├── CoffeeTrackerApp.swift
│ ├── CoffeeTrackerView.swift
│ ├── ComplicationController.swift
│ ├── ContentView.swift
│ ├── DrinkListView.swift
│ ├── HostingController.swift
│ ├── CoffeeData.swift
│ ├── Drink.swift
│ ├── DrinkType.swift
│ └── Info.plist
├── Coffee Tracker WatchKit App/
│ └── Info.plist
└── Coffee Tracker.xcodeproj/
└── .xcodesamplecode.plist
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 5 project/configuration file(s) and 10 source declaration(s).
Overall architecture
flowchart LR
N1["CoffeeTrackerApp"]
N2["ContentView"]
N3["ClockKit APIs"]
N1 --> N2
N2 --> N3
Reference code
Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift:10 — architecture anchor
@main
struct CoffeeTrackerApp: 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 ClockKit.
Ownership and state
classDiagram
CoffeeTrackerView o-- CoffeeData : coffeeData
Complication *-- String : identifier
Complication *-- String : displayName
Complication *-- Complication : caffeine
Ownership evidence
Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift:14 — stored dependency or nearest verified ownership anchor
struct CoffeeTrackerView: View {
// ...
@EnvironmentObject var coffeeData: CoffeeData
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
CoffeeTrackerView |
CoffeeData (coffeeData) |
receives environment-provided state | The environment provider is authoritative |
Complication |
String (identifier) |
owns value state | Initialized by the owner; the binding is immutable |
Complication |
String (displayName) |
owns value state | Initialized by the owner; the binding is immutable |
Complication |
Complication (caffeine) |
creates and retains | 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
Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift:11 — representative type boundary
struct CoffeeTrackerApp: App {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
CoffeeTrackerApp |
Application entry and top-level composition | App |
CoffeeTrackerView |
User-interface presentation and input forwarding | View |
ComplicationController |
View lifecycle, callbacks, and feature coordination | NSObject, CLKComplicationDataSource |
ContentView |
User-interface presentation and input forwarding | View |
DrinkListView |
User-interface presentation and input forwarding | View |
HostingController |
View lifecycle, callbacks, and feature coordination | WKHostingController |
Complication |
Represents a feature value or composable behavior | Concrete collaborators/imported frameworks |
CoffeeData |
Represents feature data | ObservableObject |
Drink |
Represents a feature value or composable behavior | Hashable, Codable |
DrinkType |
Defines a closed set of feature states or choices | Int, CaseIterable, Identifiable |
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 |
|---|---|---|---|
background (Coffee Tracker WatchKit Extension/CoffeeData.swift:33) |
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. |
currentDrinks (Coffee Tracker WatchKit Extension/CoffeeData.swift:39) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
savedValue (Coffee Tracker WatchKit Extension/CoffeeData.swift:55) |
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. |
currentMGCaffeine (Coffee Tracker WatchKit Extension/CoffeeData.swift:59) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
Reference code
Coffee Tracker WatchKit Extension/CoffeeData.swift:33 — representative boundary
class CoffeeData: ObservableObject {
// ...
private var background = DispatchQueue(label: "Background Queue",
qos: .userInitiated)
// ...
}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, HostingController |
The source’s Controller 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 | Coffee Tracker WatchKit Extension/ComplicationController.swift:10 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Delegate or data-source callbacks | Coffee Tracker WatchKit Extension/ComplicationController.swift:10 |
Callback protocols invert event delivery back into the sample’s owner. |
| SwiftUI environment injection | Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift:14 |
The environment supplies state or a capability without threading it through every initializer. |
Naming conventions
- Types: App: CoffeeTrackerApp; Controller: ComplicationController, HostingController; View: CoffeeTrackerView, ContentView, DrinkListView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
colorForCaffeineDose,colorForDailyDrinkCount,getTimelineEndDate,getPrivacyBehavior,getComplicationDescriptors,getCurrentTimelineEntry,getTimelineEntries,getLocalizableSampleTemplate. - Files:
Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift,Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift,Coffee Tracker WatchKit Extension/ComplicationController.swift,Coffee Tracker WatchKit Extension/ContentView.swift,Coffee Tracker WatchKit Extension/DrinkListView.swift,Coffee Tracker WatchKit Extension/HostingController.swift.
Architecture takeaways
CoffeeTrackerAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, ClockKit 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 |
|---|---|
Coffee Tracker WatchKit Extension/CoffeeTrackerApp.swift |
CoffeeTrackerApp |
Coffee Tracker WatchKit Extension/CoffeeTrackerView.swift |
CoffeeTrackerView, CoffeeTrackerView_Previews |
Coffee Tracker WatchKit Extension/ComplicationController.swift |
ComplicationController, Complication |
Coffee Tracker WatchKit Extension/ContentView.swift |
ContentView, ContentView_Previews |
Coffee Tracker WatchKit Extension/DrinkListView.swift |
DrinkListView, DrinkListView_Previews |
Coffee Tracker WatchKit Extension/HostingController.swift |
HostingController |
Coffee Tracker WatchKit Extension/CoffeeData.swift |
CoffeeData |
Coffee Tracker WatchKit Extension/Drink.swift |
Drink |
Coffee Tracker WatchKit Extension/DrinkType.swift |
DrinkType |