The HealthKit framework is a central component of the Apple health ecosystem that aggregates data from iPhone, Apple Watch, and third-party devices in a secure local storage. According to Apple Developer Documentation, 2025, the platform supports over 100 data types — from physical activity and sleep to lab tests and cardiovascular indicators. A single repository of medical information ensures seamless synchronization between applications with granular access control for each data type.
Key Takeaways
HealthKit is a framework from Apple, introduced in 2014 alongside iOS 8, designed for centralized management of user health and fitness data. The platform serves as a unified repository where applications and devices can write and read medical information.
Unlike third-party solutions, HealthKit is built directly into the iOS operating system, ensuring high performance and security at the hardware level. Applications do not have direct access to each other — all operations go through the central HKHealthStore.
According to Apple WWDC 2024, over 87% of iPhone users in the US have used the built-in Health app at least once, which is based on HealthKit. The ecosystem includes thousands of third-party applications — from fitness trackers to telemedicine services.
The HealthKit architecture is built on the principle of a multi-level storage with isolated containers for each data source. At the lower level is a SQLite database encrypted with hardware AES-256. At the upper level is HKHealthStore — the unified interaction interface.
Each record contains metadata: the HKSource source, the HKDevice device, date, time, and an iCloud synchronization flag. The system automatically deduplicates duplicate records from the same source, preventing data distortion.
Data is grouped by types — HKQuantityType for numerical indicators (heart rate, steps, calories) and HKCategoryType for categorical events (sleep, symptoms, menstrual cycle). This structure allows flexible querying of any parameter combinations through HKSampleQuery or HKStatisticsQuery.
HealthKit supports over 100 standardized types of data, divided into categories: physical activity, nutrition, sleep, cardiovascular system, reproductive health, lab results, and vital signs. Each type has an HKUnit measurement unit and an access level.
Developers can also create custom correlations via HKCorrelation — a group of related measurements. For example, a meal record can include calories, proteins, fats, and carbohydrates as a single object. For sequential measurements such as glucose levels, HKSeriesSample is used.
Working with HealthKit starts with defining HKHealthStore — a singleton that is automatically created when the framework is imported. Through the store, the application checks whether the platform is available on the device, as support may be absent on iPad and iPod touch. It is also important to note that HealthKit is not available on Mac Catalyst — macOS requires a separate implementation.
import HealthKit
let healthStore = HKHealthStore()
let stepType = HKQuantityType
.quantityType(forIdentifier: .stepCount)
let heartRateType = HKQuantityType
.quantityType(forIdentifier: .heartRate)
let typesToRead: Set = [stepType, heartRateType]
HealthKit functions as a mediator between data sources and applications, using an asynchronous publish-subscribe model. The source application writes data through HKHealthStore, and subscriber applications receive notifications of new records via HKObserverQuery, which runs in the background.
The framework supports background synchronization via iCloud: if the user is signed in, HealthKit automatically distributes data to all Apple devices in real time. When there is no network, changes are buffered locally and synchronized when the connection is restored without data loss.
According to Apple, the synchronization delay between iPhone and Apple Watch is less than 30 seconds for activity data. For other types — sleep, nutrition, lab results — synchronization occurs on a schedule with an interval of up to 15 minutes to save battery life.
HKHealthStore is the central singleton through which all operations are performed: saving via saveObject, reading via execute, and deleting via deleteObject. Each operation is asynchronous and returns a result through a closure, requiring proper error handling.
Queries are divided into several types: HKSampleQuery for retrieving records by criteria, HKStatisticsQuery for aggregated data — sum, average, minimum, maximum — and HKObserverQuery for tracking changes in real time. For periodic background updates, HKHeartbeatSeriesQuery is used.
let type = HKQuantityType
.quantityType(forIdentifier: .stepCount)
let now = Date()
let start = Calendar.current
.date(
byAdding: .day,
value: -7,
to: now
)
let predicate = HKQuery
.predicateForSamples(
withStart: start,
end: now,
options: .strictStartDate
)
let query = HKSampleQuery(
sampleType: type,
predicate: predicate,
limit: 100
) { _, samples, _ in
for sample in samples as [HKQuantitySample] {
print(sample.quantity)
}
}
healthStore.execute(query)
Integrating HealthKit begins with enabling the HealthKit capability in Xcode and adding the entitlement to the project. After that, the application requests permission to access specific data types through the requestAuthorization call. Important: HealthKit is not available on the simulator and requires a physical device with iOS.
The integration process includes three stages: defining data types, requesting authorization, and performing read and write operations. Each stage is asynchronous and must handle errors — the user can deny access to any data type in the system dialog with toggles.
According to Apple research, applications with HealthKit integration show 40% higher user engagement levels. The key success factor is explaining why the app needs specific health data in the authorization request description.
The authorization request is made once at first launch. The application specifies two sets of types — for reading and for writing. The user sees a system dialog with toggles for each data type and can selectively grant access, denying unnecessary categories.
let typesToWrite: Set = [
HKQuantityType
.quantityType(
forIdentifier: .dietaryEnergyConsumed
)
]
let typesToRead: Set = [
HKQuantityType
.quantityType(
forIdentifier: .stepCount
)
]
healthStore.requestAuthorization(
toShare: typesToWrite,
read: typesToRead
) { success, error in
if success {
print("Authorization obtained")
}
}
HealthKit implements a multi-layer security model including hardware encryption, application sandboxing, and granular permissions. All health data is stored encrypted on the device and is not transmitted to iCloud without separate user consent, which is requested once.
A key feature is the Intent mechanism: the application does not have constant background access to data. Each read or write request is verified by the operating system, and the user can revoke permission at any time through Settings — Privacy — Health without needing to reinstall the application.
Apple strictly regulates the use of HealthKit in the App Store Review Guidelines. The application cannot transfer HealthKit data to third parties without explicit consent, cannot use it for advertising or targeting, and cannot store it longer than necessary for the stated functionality.
HealthKit has several limitations: the maximum database size on the device is 1 GB, the limit on the number of records in a single query is 1000, and the minimum interval between identical data types is 1 second. The framework also limits background updates — no more than 60 HKObserverQuery triggers per day.
These limitations are offset by performance: reading 1000 records takes an average of 50–100 milliseconds, and writing a single record takes less than 10 milliseconds. For large data volumes, it is recommended to use HKStatisticsCollectionQuery with pre-aggregation rather than fetching individual records. HealthKit processes queries asynchronously — the application is not blocked while waiting for data from HKHealthStore.
Frequently Asked Questions
HealthKit is supported on all devices with iOS 8 and later, including iPhone, iPad, and iPod touch. Apple Watch automatically transmits data through the paired iPhone. Third-party devices — fitness bands, scales, blood pressure monitors — can write data through the HealthKit API if a corresponding application is available.
Yes, the Health app allows exporting all data in XML format through the “Export Health Data” function. Developers can programmatically read any permitted types through HKSampleQuery and export to their own format. Health data cannot be transferred to third-party servers without explicit user consent.
The user can delete data through the Health app or through the source application that recorded it. After deletion, data cannot be restored — HealthKit does not have a trash bin. The delete operation is irreversible, so applications are recommended to request confirmation before executing deleteObject.
HealthKit is designed for storing and sharing user health data, while ResearchKit is a framework for conducting medical research. ResearchKit uses HealthKit as one of its data sources but adds modules for informed consent, questionnaires, and active tasks for collecting research data.
Yes, applications using HealthKit must comply with App Store Review Guidelines, section 5.1.1 — Medical and Health Data. Explicit description of data usage in the application, a privacy policy, prohibition on advertising use of data, and encryption during network transmission are required.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also