Scheduling an alarm with AlarmKit
At a glance
| Item | Summary |
|---|---|
| Purpose | Create prominent alerts at specified dates for your iOS app. |
| App architecture | A Swift sample with the source-visible chain AlarmKitScheduleAndAlertApp → ContentView → ViewModel → AlarmKit APIs. |
| Main patterns | Model-View-ViewModel, Binding-based state propagation, Actor-isolated state |
| Project style | 8 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── AlarmKit-ScheduleAndAlert/
├── AlarmKit-ScheduleAndAlert/
│ ├── AlarmKitScheduleAndAlertApp.swift
│ ├── ContentView.swift
│ ├── AppIntents.swift
│ ├── ViewModel.swift
│ ├── AlarmForm.swift
│ ├── AlarmMetadata.swift
│ └── Info.plist
├── AlarmLiveActivity/
│ ├── AlarmLiveActivityBundle.swift
│ ├── AlarmLiveActivity.swift
│ └── Info.plist
└── AlarmKit-ScheduleAndAlert.xcodeproj/
├── .xcodesamplecode.plist
└── project.pbxproj
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 21 source declaration(s).
Overall architecture
flowchart LR
N1["AlarmKitScheduleAndAlertApp"]
N2["ContentView"]
N3["ViewModel"]
N4["AlarmKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AlarmKitScheduleAndAlertApp.swift:10 — architecture anchor
@main
struct AlarmKitScheduleAndAlertApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}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 AlarmKit.
Ownership and state
classDiagram
ContentView *-- ViewModel : viewModel
AlarmCell o-- Alarm : alarm
AlarmCell o-- LocalizedStringResource : label
AlarmAddView *-- AlarmForm : userInput
Ownership evidence
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift:12 — stored dependency or nearest verified ownership anchor
@State private var viewModel = ViewModel()| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ContentView |
ViewModel (viewModel) |
owns wrapper-managed state | Owning lexical scope |
AlarmCell |
Alarm (alarm) |
stores or receives | App/module collaborators |
AlarmCell |
LocalizedStringResource (label) |
stores or receives | App/module collaborators |
AlarmAddView |
AlarmForm (userInput) |
owns wrapper-managed state | Owning lexical scope |
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
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AlarmKitScheduleAndAlertApp.swift:11 — representative type boundary
struct AlarmKitScheduleAndAlertApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AlarmKitScheduleAndAlertApp |
Application entry and top-level composition | App |
ContentView |
User-interface presentation and input forwarding | View |
AlarmAddView |
User-interface presentation and input forwarding | View |
TimePickerView |
User-interface presentation and input forwarding | View |
ViewModel |
UI-facing state and feature coordination | Concrete collaborators/imported frameworks |
AlarmProgressView |
User-interface presentation and input forwarding | View |
ButtonView |
User-interface presentation and input forwarding | Concrete collaborators/imported frameworks |
AlarmCell |
Represents a feature value or composable behavior | View |
AlarmLiveActivityBundle |
Represents a feature value or composable behavior | WidgetBundle |
PauseIntent |
Represents a feature value or composable behavior | LiveActivityIntent |
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 |
|---|---|---|---|
viewModel (AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift:12) |
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. |
showAddSheet (AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.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. |
dismiss (AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift:146) |
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. |
viewModel (AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift:147) |
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. |
Reference code
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift:12 — representative boundary
@State private var viewModel = ViewModel()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 | AlarmKitScheduleAndAlertApp |
The source’s App suffix makes this role explicit. |
| User-interface presentation and input forwarding | AlarmAddView, AlarmProgressView, ButtonView, ContentView |
The source’s View suffix makes this role explicit. |
| UI-facing state and feature coordination | ViewModel |
The source’s ViewModel suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ViewModel.swift:12 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| Binding-based state propagation | AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift:265 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
| Actor-isolated state | AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ViewModel.swift:16 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: AlarmKitScheduleAndAlertApp; View: AlarmAddView, AlarmProgressView, ButtonView, ContentView, TimePickerView; ViewModel: ViewModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
alarmList,pickerRow,perform,fetchAlarms,scheduleAlarm,scheduleAlertOnlyExample,scheduleCountdownAlertExample,scheduleCustomButtonAlertExample. - Files:
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AlarmKitScheduleAndAlertApp.swift,AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift,AlarmKit-ScheduleAndAlert/AlarmLiveActivity/AlarmLiveActivityBundle.swift,AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ViewModel.swift,AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AlarmForm.swift,AlarmKit-ScheduleAndAlert/AlarmLiveActivity/AlarmLiveActivity.swift.
Architecture takeaways
AlarmKitScheduleAndAlertAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches AlarmKit, SwiftUI, AppIntents, WidgetKit 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 |
|---|---|
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AlarmKitScheduleAndAlertApp.swift |
AlarmKitScheduleAndAlertApp |
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ContentView.swift |
ContentView, AlarmCell, AlarmAddView, TimePickerView |
AlarmKit-ScheduleAndAlert/AlarmLiveActivity/AlarmLiveActivityBundle.swift |
AlarmLiveActivityBundle |
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AppIntents.swift |
PauseIntent, StopIntent, RepeatIntent, ResumeIntent, OpenAlarmAppIntent |
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/ViewModel.swift |
ViewModel |
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AlarmForm.swift |
AlarmForm, SecondaryButtonOption, CountdownInterval |
AlarmKit-ScheduleAndAlert/AlarmLiveActivity/AlarmLiveActivity.swift |
AlarmLiveActivity, AlarmProgressView, AlarmControls, ButtonView |
AlarmKit-ScheduleAndAlert/AlarmKit-ScheduleAndAlert/AlarmMetadata.swift |
CookingData, Method |