Skip to main content

HealthKit

PrismHealthKit provides a Sendable, actor-based wrapper around Apple’s HealthKit framework. Query health samples, compute statistics, and write data without managing HKHealthStore or HKSampleQuery directly.

Permissions

Request authorization for specific data types:
Request Health Permissions

Supported Data Types

Querying Samples

Fetch individual health samples within a date range:
Query Heart Rate

PrismHealthSample

Statistics

Get aggregated statistics (sum, average, min, max) over a period:
Daily Step Statistics

PrismHealthStatistics

Writing Data

Save health samples to HealthKit:
Save Body Mass
Writing to HealthKit requires explicit write authorization for each data type. Always request write permissions before attempting to save.

Observing Changes

Stream real-time updates when new samples are added:
Observe Heart Rate
HealthKit data is privacy-sensitive. Your app must include the NSHealthShareUsageDescription and NSHealthUpdateUsageDescription keys in Info.plist.