Loading...
Loading...
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.
npx skill4agent add nonameplum/agent-skills swift-health-kitArticles/healtkit.mdHKHealthStoreHKQuantitySampleHKWorkoutHKObserverQuery| 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 |
NSHealthShareUsageDescriptionNSHealthUpdateUsageDescriptionHKHealthStore.isHealthDataAvailable()HKHealthStorerequestAuthorization(toShare:read:)HKSampleTypeHKQuantityTypeHKSampleQueryDescriptorHKStatisticsQueryDescriptorHKHealthStoreHKQuantitySampleHKCategorySampleHKCorrelation.count().meter()healthStore.save(_:withCompletion:)authorizationStatus(for:)enableBackgroundDelivery(for:frequency:withCompletion:)HKObserverQueryhealthStore.execute(_:)HKWorkoutConfigurationHKWorkoutSessionHKLiveWorkoutBuilderendCollection(withEnd:completion:)| Type | Purpose |
|---|---|
| Central access point; authorization, queries, saving |
| Numeric health data (steps, heart rate, weight) |
| Enumerated data (sleep analysis, menstrual flow) |
| Composite samples (food, blood pressure) |
| Fitness activity with duration, energy, distance |
| Long-running query for store changes |
| Track additions/deletions since last anchor |
| Aggregate calculations (sum, avg, min, max) |
| Time-bucketed statistics for charts |
authorizationStatus(for:)errorNotPermissibleForGuestUserModeisHealthDataAvailable()falseearliestPermittedSampleDate()HKError.CodeerrorHealthDataUnavailableerrorHealthDataRestrictederrorAuthorizationNotDeterminederrorAuthorizationDeniederrorNotPermissibleForGuestUserModeerrorRequiredAuthorizationDeniedHealthKitUIimport HealthKitUI
.healthDataAccessRequest(
store: healthStore,
shareTypes: allTypes,
readTypes: allTypes,
trigger: trigger
) { result in
// Handle authorization result
}HKDeletedObjectHKWorkoutActivity