swift-health-kit
Apple HealthKit framework for health and fitness data. Use for reading/writing health samples, workout data, authorization flows, observer queries, background…
от nonameplum★ 17 звёзд на GitHub
Установить swift-health-kit в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
HealthKit
What to open
- Use
Articles/healtkit.mdfor complete HealthKit documentation (188 pages consolidated). - Search within the file by section URLs or keywords like
HKHealthStore,HKQuantitySample,HKWorkout,HKObserverQuery.
Document structure
The documentation file is organized by Apple documentation URLs as section headers. Key sections:
| Line | Topic |
|---|---|
| ~11 | Framework overview |
| ~115 | About the HealthKit framework (architecture) |
| ~246 | Setting up HealthKit (entitlements, Info.plist) |
| ~357 | Authorizing access to health data |
| ~517 | Protecting user privacy |
| ~586 | Saving data to HealthKit |
| ~673 | Reading data from HealthKit (queries) |
| ~760 | HKHealthStore API reference |
| ~968 | Creating a Mobility Health App (sample project) |
| ~1025 | Data types (type identifiers) |
| ~1614 | Samples (HKSample, quantity, category, correlations) |
| ~1871 | Queries (sample, anchored, statistics, observer) |
| ~2146 | Visualizing State of Mind in visionOS |
| ~2203 | Logging symptoms associated with a medication |
| ~2278 | Workouts and activity rings |
| ~2449 | HKError and error handling |
| ~3152 | Executing observer queries |
| ~4778 | Background delivery (HKUpdateFrequency) |
| ~5974 | HKObjectType and subclasses |
| ~7264 | HKSampleType reference |
Setup checklist
- Add HealthKit capability in Xcode (enable Clinical Health Records only if needed).
- Add
NSHealthShareUsageDescriptionandNSHealthUpdateUsageDescriptionto Info.plist. - Check
HKHealthStore.isHealthDataAvailable()before any HealthKit calls. - Create a single
HKHealthStoreinstance and retain it for the app's lifetime. - Request authorization with
requestAuthorization(toShare:read:)before reading or writing.
Common workflows
Reading data
- Create the appropriate
HKSampleTypeorHKQuantityType. - Build a query descriptor (e.g.,
HKSampleQueryDescriptor,HKStatisticsQueryDescriptor). - Execute the query against
HKHealthStore. - Handle results on a background queue; dispatch to main for UI updates.
Saving data
- Create an
HKQuantitySample,HKCategorySample, orHKCorrelation. - Use matching units for the data type (e.g.,
.count()for steps,.meter()for distance). - Call
healthStore.save(_:withCompletion:). - Check
authorizationStatus(for:)before saving to catch permission issues early.
Background delivery
- Enable Background Modes in Xcode (Background fetch).
- Call
enableBackgroundDelivery(for:frequency:withCompletion:)for each data type. - Register an
HKObserverQuerywith an update handler. - When woken, call
healthStore.execute(_:)to re-run the query.
Workouts
- Create an
HKWorkoutConfigurationwith activity type and location. - Start a workout session on Apple Watch with
HKWorkoutSession. - Use
HKLiveWorkoutBuilderto collect real-time samples. - End the session and save the workout with
endCollection(withEnd:completion:).
Key types
| Type | Purpose |
|---|---|
HKHealthStore |
Central access point; authorization, queries, saving |
HKQuantitySample |
Numeric health data (steps, heart rate, weight) |
HKCategorySample |
Enumerated data (sleep analysis, menstrual flow) |
HKCorrelation |
Composite samples (food, blood pressure) |
HKWorkout |
Fitness activity with duration, energy, distance |
HKObserverQuery |
Long-running query for store changes |
HKAnchoredObjectQueryDescriptor |
Track additions/deletions since last anchor |
HKStatisticsQueryDescriptor |
Aggregate calculations (sum, avg, min, max) |
HKStatisticsCollectionQueryDescriptor |
Time-bucketed statistics for charts |
Privacy and authorization
- HealthKit uses fine-grained authorization per data type.
- Apps cannot detect if read permission was denied; queries simply return no data.
- Use
authorizationStatus(for:)to check write permission before saving. - Guest User sessions on visionOS restrict mutations; handle
errorNotPermissibleForGuestUserMode. - Never use HealthKit data for advertising or sell it to third parties.
Platform availability
- iPhone/Apple Watch/visionOS: Full HealthKit store with sync.
- iPadOS 17+: Has its own HealthKit store.
- iPadOS 16 and earlier / macOS 13+: Framework available but
isHealthDataAvailable()returnsfalse. - Use
earliestPermittedSampleDate()on Apple Watch to find oldest available data.
Error handling
Check for these common HKError.Code values:
errorHealthDataUnavailable– Device doesn't support HealthKit.errorHealthDataRestricted– Enterprise or parental restrictions.errorAuthorizationNotDetermined– Authorization not yet requested.errorAuthorizationDenied– User denied write permission.errorNotPermissibleForGuestUserMode– Vision Pro guest session restriction.errorRequiredAuthorizationDenied– Required clinical record types denied.
SwiftUI integration
Use the `
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- Articles/healthkit.md
- Articles/healtkit.md
FAQ
Что делает скилл swift-health-kit?
Apple HealthKit framework for health and fitness data. Use for reading/writing health samples, workout data, authorization flows, observer queries, background delivery, clinical records, activity rings, and integrating with the Health app across iPhone, Apple Watch, iPad, and visionOS.
Как установить скилл swift-health-kit?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл swift-health-kit запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…