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

Create accessible experiences for watchOS

At a glance

Item Summary
Purpose Learn how to make your watchOS app more accessible.
App architecture A Swift sample with the source-visible chain PlantCareAppPlantContentViewSwiftUI / ClockKit APIs.
Main patterns View-controller organization, Delegate or data-source callbacks, SwiftUI environment injection, Binding-based state propagation, Publisher-backed observable state
Project style 6 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue.main.asyncAfter; none alone proves a background thread.
State/event model Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published.
Key frameworks/packages SwiftUI, ClockKit, Foundation, os; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── PlantCare/
│   ├── PlantCare WatchKit Extension/
│   │   ├── PlantCareApp.swift
│   │   ├── PlantCellView.swift
│   │   ├── PlantEditView.swift
│   │   ├── PlantContentView.swift
│   │   ├── ComplicationController.swift
│   │   ├── PlantData.swift
│   │   └── Info.plist
│   └── PlantCare.xcodeproj/
│       ├── .xcodesamplecode.plist
│       └── project.pbxproj
└── Configuration/
    └── SampleCode.xcconfig

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 4 project/configuration file(s) and 19 source declaration(s).

Overall architecture

Reference code

PlantCare/PlantCare WatchKit Extension/PlantCareApp.swift:10 — architecture anchor

@main
struct PlantCareApp: App {
    @StateObject var plantData = PlantData.shared

    var body: some Scene {
        WindowGroup {
            NavigationView {
                PlantContentView()
                    .environmentObject(plantData)
            }
        }
    }
}

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 watchOS-Apps.

Ownership and state

Ownership evidence

PlantCare/PlantCare WatchKit Extension/PlantCellView.swift:11 — stored dependency or nearest verified ownership anchor

struct PlantCellView: View {
    @EnvironmentObject var plantData: PlantData
    // ...
}
Owner Object or state Relationship Mutation authority
PlantCellView PlantData (plantData) receives environment-provided state The environment provider is authoritative
PlantCellView Plant (plant) stores or receives App/module collaborators
PlantContainerView Plant (plant) borrows mutable state The upstream binding owner is authoritative
PlantViewHorizontal Plant (plant) borrows mutable state The upstream binding owner 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.

Concern Source mechanism Verified placement or handoff Evidence
Queue scheduling DispatchQueue.main.asyncAfter The source addresses the main dispatch queue. PlantCare/PlantCare WatchKit Extension/PlantCellView.swift:116

@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

PlantCare/PlantCare WatchKit Extension/PlantCellView.swift:116 — representative execution boundary

            self.isTapped.toggle()
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.isTapped.toggle()
            }

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. PlantCare/PlantCare WatchKit Extension/PlantCareApp.swift:12
State propagation ObservableObject ObservableObject supplies an observation contract. PlantCare/PlantCare WatchKit Extension/PlantData.swift:158
State propagation @Published A published property can emit owner-controlled changes. PlantCare/PlantCare WatchKit Extension/PlantData.swift:159
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. PlantCare/PlantCare WatchKit Extension/PlantCareApp.swift:8
Source import ClockKit The cited file imports this module; runtime use and architectural role are not inferred. PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:8
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. PlantCare/PlantCare WatchKit Extension/PlantData.swift:8
Source import os The cited file imports this module; runtime use and architectural role are not inferred. PlantCare/PlantCare WatchKit Extension/PlantData.swift:9

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

PlantCare/PlantCare WatchKit Extension/PlantCareApp.swift:11 — representative type boundary

@main
struct PlantCareApp: App {
    @StateObject var plantData = PlantData.shared
    // ...
}
Type Responsibility Depends on or conforms to
PlantCareApp Application entry and top-level composition App
PlantCellView User-interface presentation and input forwarding View
PlantContainerView User-interface presentation and input forwarding View
PlantEditView User-interface presentation and input forwarding View
PlantContentView User-interface presentation and input forwarding View
ComplicationController View lifecycle, callbacks, and feature coordination NSObject, CLKComplicationDataSource
PlantViewHorizontal Represents a feature value or composable behavior View
PlantViewVertical Represents a feature value or composable behavior View
PlantImage Represents a feature value or composable behavior View
PlantTaskLabel Represents a feature value or composable behavior View

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
createTimelineEntry (PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:78) 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.
createTemplate (PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:83) 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.
createModularSmallTemplate (PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:118) 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.
createModularLargeTemplate (PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:133) 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

PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:78 — representative boundary

    private func createTimelineEntry(forComplication complication: CLKComplication, date: Date) -> CLKComplicationTimelineEntry {
        let template = createTemplate(forComplication: complication, date: date)
        return CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
    }

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 PlantCareApp The source’s App suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination ComplicationController The source’s Controller suffix makes this role explicit.
User-interface presentation and input forwarding PlantCellView, PlantContainerView, PlantContentView, PlantEditView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:9 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Delegate or data-source callbacks PlantCare/PlantCare WatchKit Extension/ComplicationController.swift:9 Callback protocols invert event delivery back into the sample’s owner.
SwiftUI environment injection PlantCare/PlantCare WatchKit Extension/PlantCellView.swift:11 The environment supplies state or a capability without threading it through every initializer.
Binding-based state propagation PlantCare/PlantCare WatchKit Extension/PlantCellView.swift:36 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Publisher-backed observable state PlantCare/PlantCare WatchKit Extension/PlantData.swift:159 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: PlantCareApp; Controller: ComplicationController; View: PlantCellView, PlantContainerView, PlantContentView, PlantEditView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: getComplicationDescriptors, handleSharedComplicationDescriptors, getTimelineEndDate, getPrivacyBehavior, getCurrentTimelineEntry, getTimelineEntries, getLocalizableSampleTemplate, createTimelineEntry.
  • Files: PlantCare/PlantCare WatchKit Extension/PlantCareApp.swift, PlantCare/PlantCare WatchKit Extension/PlantCellView.swift, PlantCare/PlantCare WatchKit Extension/PlantEditView.swift, PlantCare/PlantCare WatchKit Extension/PlantContentView.swift, PlantCare/PlantCare WatchKit Extension/ComplicationController.swift, PlantCare/PlantCare WatchKit Extension/PlantData.swift.

Architecture takeaways

  • PlantCareApp is 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
PlantCare/PlantCare WatchKit Extension/PlantCareApp.swift Cited implementation, PlantCareApp, SwiftUI state property wrapper, SwiftUI
PlantCare/PlantCare WatchKit Extension/PlantCellView.swift Cited implementation, DispatchQueue.main.asyncAfter, PlantCellView, PlantContainerView, PlantViewHorizontal, PlantViewVertical, PlantImage, PlantTaskLabel, PlantButton, PlantTaskList, PlantTaskButtons, PlantCellView_Previews
PlantCare/PlantCare WatchKit Extension/ComplicationController.swift Cited implementation, ComplicationController, ClockKit
PlantCare/PlantCare WatchKit Extension/PlantData.swift Cited implementation, ObservableObject, @Published, Foundation, os, SunlightLevel, Plant, PlantTask, PlantData
PlantCare/PlantCare WatchKit Extension/PlantEditView.swift PlantEditView, PlantTaskFrequency, CustomCounter, PlantEditView_Previews
PlantCare/PlantCare WatchKit Extension/PlantContentView.swift PlantContentView, ContentView_Previews