HealthKit: The Secure Vault for User Health Data

HealthKit is a secure, centralized database for user health data, not a sensor. Your app requests permission to read or write data like steps or workouts, which the OS manages. The footgun is assuming access; users grant permissions per data type.
WHY IT EXISTS: Before HealthKit, every fitness and health app was a data silo. A user's running app data couldn't be combined with their nutrition app data. HealthKit was created to be a single, user-controlled source of truth, allowing different apps to contribute to a unified health profile.
THE MENTAL MODEL: Think of HealthKit as a secure vault for health data, managed by the operating system, not your app. Your app is a temporary visitor that must ask the user for specific keys (permissions) to read from or write to the vault. You don't own the database; you are a guest with temporary, revocable privileges.
HOW IT WORKS: Your app first declares the specific data types it wants to access in its configuration, like step counts or workout duration. When needed, you present a system prompt to the user requesting authorization for those types. If granted, you use the HKHealthStore API to construct and execute queries to fetch data or to create and save new data samples. All data is strongly typed, ensuring consistency (e.g., distance is a length, calories are energy).
WHEN TO USE IT: Use HealthKit whenever your app reads or writes health-related information. This is essential for workout apps, diet trackers, mindfulness apps, and apps connecting to medical devices. It provides a standard, secure way to interact with a user's health data and enriches your app with data from other sources.
WHEN NOT TO USE IT: Do not use HealthKit for storing non-health-related data; this is a violation of Apple's guidelines and will lead to app rejection. Also, if your app needs to be truly cross-platform (e.g., available on Android), relying solely on HealthKit is not a complete solution, as it's an Apple-exclusive framework.
ONE CANONICAL EXAMPLE: A third-party running app finishes tracking a run. It creates an HKWorkout object, specifying the activity type as '.running', the start and end times, total distance covered, and total energy burned. It then saves this workout object to the HKHealthStore. Immediately, this workout appears in the user's Fitness app and contributes to their daily activity rings, because both apps are reading from the same central store.
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.