Visualizing HealthKit State of Mind in visionOS
At a glance
| Item | Summary |
|---|---|
| Purpose | Incorporate HealthKit State of Mind into your app and visualize the data in visionOS. |
| App architecture | A Swift sample with the source-visible chain HKStateOfMindDataSampleApp → TabsView → HealthStore → CalendarQualityScoreProvider → HealthKit APIs. |
| Main patterns | Central store, Binding-based state propagation, Actor-isolated state |
| Project style | 33 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── HKStateOfMindDataSampleApp/
└── HKStateOfMindDataSampleApp/
├── HKStateOfMindDataSampleApp.swift
├── Models/
│ ├── Insights/
│ │ └── InsightsModels.swift
│ ├── Calendars/
│ │ └── CalendarModel.swift
│ ├── Stores/
│ │ └── HealthStore.swift
│ └── Today/
│ └── EventModel.swift
├── Views/
│ ├── Charts/
│ │ └── CalendarChartsView.swift
│ ├── Authorization/
│ │ └── AuthorizationGatedView.swift
│ ├── Reflection/
│ │ └── ReflectionCurrentEmojiPickerView.swift
│ ├── TabsView.swift
│ └── Today/
│ └── CalendarScoreView.swift
└── Data Sources/
├── CalendarQualityScoreProvider.swift
└── WorkLifeBalanceScoreProvider.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 5 project/configuration file(s) and 48 source declaration(s).
Overall architecture
flowchart LR
N1["HKStateOfMindDataSampleApp"]
N2["TabsView"]
N3["HealthStore"]
N4["CalendarQualityScoreProvider"]
N5["HealthKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp.swift:12 — architecture anchor
@main
struct HKStateOfMindDataSampleApp: 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 HealthKit.
Ownership and state
classDiagram
HKStateOfMindDataSampleApp *-- Calendars : calendars
HKStateOfMindDataSampleApp *-- Bool : eventsAuthorized
HKStateOfMindDataSampleApp *-- Bool : healthDataAuthorized
InsightModel *-- UUID : id
Ownership evidence
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp.swift:17 — stored dependency or nearest verified ownership anchor
@State var calendars = Calendars(calendarModels: [])
/* Authorization */
@State var eventsAuthorized: Bool?
@State var toggleHealthDataAuthorization = false
@State var healthDataAuthorized: Bool?| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
HKStateOfMindDataSampleApp |
Calendars (calendars) |
owns wrapper-managed state | App/module collaborators |
HKStateOfMindDataSampleApp |
Bool (eventsAuthorized) |
owns wrapper-managed state | App/module collaborators |
HKStateOfMindDataSampleApp |
Bool (healthDataAuthorized) |
owns wrapper-managed state | App/module collaborators |
InsightModel |
UUID (id) |
owns value state | 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
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp.swift:13 — representative type boundary
struct HKStateOfMindDataSampleApp: App {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
HKStateOfMindDataSampleApp |
Application entry and top-level composition | App |
InsightModel |
Feature data or observable state | Identifiable |
CalendarChartsView |
User-interface presentation and input forwarding | View |
CalendarModel |
Feature data or observable state | Identifiable, Equatable, Hashable, Sendable |
HealthStore |
Centralized state or persistence access | Sendable |
EventModel |
Feature data or observable state | Sendable, Identifiable |
HealthKitAuthorizationGatedView |
User-interface presentation and input forwarding | Concrete collaborators/imported frameworks |
EventKitAuthorizationGatedView |
User-interface presentation and input forwarding | Concrete collaborators/imported frameworks |
ReflectionCurrentEmojiPickerView |
User-interface presentation and input forwarding | View |
TabsView |
User-interface presentation and input forwarding | 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 |
|---|---|---|---|
eventStore (HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Data Sources/CalendarFetcher.swift:21) |
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. |
deviceCalendar (HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Data Sources/CalendarFetcher.swift:22) |
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. |
CalendarFetcher (HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Data Sources/CalendarFetcher.swift:24) |
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. |
sourceToUse (HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Data Sources/CalendarFetcher.swift:152) |
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
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Data Sources/CalendarFetcher.swift:21 — representative boundary
actor CalendarFetcher {
// ...
private let eventStore: EKEventStore
// ...
}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 | HKStateOfMindDataSampleApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | CalendarModel, EventModel, InsightModel |
The source’s Model suffix makes this role explicit. |
| Supplies a capability or framework resource | CalendarQualityScoreProvider, CalendarStateOfMindDataProvider, WorkLifeBalanceScoreProvider |
The source’s Provider suffix makes this role explicit. |
| Scene lifecycle or scene-level composition | ReflectionScene |
The source’s Scene suffix makes this role explicit. |
| Centralized state or persistence access | HealthStore |
The source’s Store suffix makes this role explicit. |
| User-interface presentation and input forwarding | CalendarChartsView, CalendarScoreView, CalendarSelectorView, ChartView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Central store | HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Stores/HealthStore.swift:10 |
A store-named type centralizes feature state or persistence. |
| Binding-based state propagation | HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/Authorization/AuthorizationGatedView.swift:17 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
| Actor-isolated state | HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Data Sources/CalendarFetcher.swift:13 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: HKStateOfMindDataSampleApp; Model: CalendarModel, EventModel, InsightModel; Provider: CalendarQualityScoreProvider, CalendarStateOfMindDataProvider, WorkLifeBalanceScoreProvider; Scene: ReflectionScene; Store: HealthStore; View: CalendarChartsView, CalendarScoreView, CalendarSelectorView, ChartView, DateIntervalPaginationView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
decrement,increment. - Files:
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp.swift,HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/Charts/CalendarChartsView.swift,HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Calendars/CalendarModel.swift,HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Stores/HealthStore.swift,HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Today/EventModel.swift,HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/Reflection/ReflectionCurrentEmojiPickerView.swift.
Architecture takeaways
HKStateOfMindDataSampleAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, HealthKit, EventKit, Charts 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 |
|---|---|
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp.swift |
HKStateOfMindDataSampleApp, WindowGroupID |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Insights/InsightsModels.swift |
InsightDateInterval, InsightType, InsightModel, InsightSectionType, InsightSection |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/Charts/CalendarChartsView.swift |
CalendarChartsView, NewChartViewerButton, DateConfiguration |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Calendars/CalendarModel.swift |
CalendarModel |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Stores/HealthStore.swift |
HealthStore |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Models/Today/EventModel.swift |
EventModel |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/Authorization/AuthorizationGatedView.swift |
HealthKitAuthorizationGatedView, EventKitAuthorizationGatedView |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/Reflection/ReflectionCurrentEmojiPickerView.swift |
ReflectionCurrentEmojiPickerView, OptionButton |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/TabsView.swift |
TabsView, TabKind |
HKStateOfMindDataSampleApp/HKStateOfMindDataSampleApp/Views/Today/CalendarScoreView.swift |
CalendarScoreView, Defaults |