← ClaudeAtlas

healthkitlisted

Read, write, and query Apple Health data using HealthKit. Covers HKHealthStore authorization, sample queries, statistics queries, statistics collection queries for charts, saving HKQuantitySample data, background delivery, workout sessions with HKWorkoutSession and HKLiveWorkoutBuilder, HKUnit, and HKQuantityTypeIdentifier values. Use when integrating with Apple Health, displaying health metrics, recording workouts, or enabling background health data delivery.
dpearson2699/swift-ios-skills · ★ 730 · AI & Automation · score 80
Install: claude install-skill dpearson2699/swift-ios-skills
# HealthKit Read and write health and fitness data from the Apple Health store. Covers authorization, queries, writing samples, background delivery, and workout sessions. Targets Swift 6.3 / iOS 26+. ## Contents - [Setup and Availability](#setup-and-availability) - [Authorization](#authorization) - [Reading Data: Sample Queries](#reading-data-sample-queries) - [Reading Data: Statistics Queries](#reading-data-statistics-queries) - [Reading Data: Statistics Collection Queries](#reading-data-statistics-collection-queries) - [Writing Data](#writing-data) - [Background Delivery](#background-delivery) - [Workout Sessions](#workout-sessions) - [Common Data Types](#common-data-types) - [HKUnit Reference](#hkunit-reference) - [Common Mistakes](#common-mistakes) - [Review Checklist](#review-checklist) - [References](#references) ## Setup and Availability ### Project Configuration 1. Enable the HealthKit capability in Xcode (adds the entitlement) 2. Add `NSHealthShareUsageDescription` (read) and `NSHealthUpdateUsageDescription` (write) to Info.plist 3. For background delivery, enable the "Background Delivery" sub-capability ### Availability Check Always check availability before accessing HealthKit. iPad and some devices do not support it. ```swift import HealthKit let healthStore = HKHealthStore() guard HKHealthStore.isHealthDataAvailable() else { // HealthKit not available on this device (e.g., iPad) return } ``` Create a single `HKHealthStore` instance and reuse i