Class

HKHealth​Store

The HealthKit store acts as your link to all the data managed by HealthKit. Use a HKHealth​Store object to request permission to share or read HealthKit data. Once permission is granted, you can use the HealthKit store to save new samples to the store, or to manage the samples that your app has saved. Additionally, you can use the HealthKit store to start, stop, and manage queries.

Overview

Setting Up the HealthKit Framework

You must set up the HealthKit framework before you can access data in the HealthKit store. This includes enabling the HealthKit capabilities, verifying that HealthKit is available on the device, and requesting permission to read and write data.

For a detailed description on setting up the HealthKit framework, see Setting Up HealthKit in HealthKit.

Subclassing Notes

Like many classes in HealthKit, the HKHealth​Store class should not be subclassed.

Symbols

Accessing HealthKit

func authorization​Status(for:​ HKObject​Type)

Returns the app’s authorization status for sharing the specified data type.

class func is​Health​Data​Available()

Returns a Boolean value that indicates whether HealthKit is available on this device.

func handle​Authorization​For​Extension(completion:​ (Bool, Error?) -> Void)

Requests permission to save and read the data types specified by an extension.

Reading Characteristic Data

func biological​Sex()

Reads the user’s biological sex from the HealthKit store.

func blood​Type()

Reads the user’s blood type from the HealthKit store.

func date​Of​Birth()

Reads the user’s date of birth from the HealthKit store.

Deprecated
func date​Of​Birth​Components()

Reads the user’s date of birth from the HealthKit store.

func fitzpatrick​Skin​Type()

Reads the user’s Fitzpatrick Skin Type from the HealthKit store.

func wheelchair​Use()

Reads the user’s wheelchair use from the HealthKit store.

Working with HealthKit Objects

func delete(HKObject, with​Completion:​ (Bool, Error?) -> Void)

Deletes the specified object from the HealthKit store.

func delete([HKObject], with​Completion:​ (Bool, Error?) -> Void)

Deletes the specified objects from the HealthKit store.

func delete​Objects(of:​ HKObject​Type, predicate:​ NSPredicate, with​Completion:​ (Bool, Int, Error?) -> Void)

Deletes objects saved by this application that match the provided type and predicate.

func earliest​Permitted​Sample​Date()

Returns the earliest date permitted for samples.

func save(HKObject, with​Completion:​ (Bool, Error?) -> Void)

Saves the provided object to the HealthKit store.

func save([HKObject], with​Completion:​ (Bool, Error?) -> Void)

Saves an array of objects to the HealthKit store.

Working with Workouts

func add([HKSample], to:​ HKWorkout, completion:​ (Bool, Error?) -> Void)

Associates the provided samples with the specified workout.

func split​Total​Energy(HKQuantity, start:​ Date, end:​ Date, results​Handler:​ (HKQuantity?, HKQuantity?, Error?) -> Void)

Calculates the active and resting energy burned based on the total energy burned over the given duration.

Querying HealthKit Data

func execute(HKQuery)

Starts executing the provided query.

func stop(HKQuery)

Stops a long-running query.

Accessing the Preferred Units

Managing Workout Sessions

func start(HKWorkout​Session)

Starts a workout session for the current app.

func pause(HKWorkout​Session)

Pauses the provided workout session.

func resume​Workout​Session(HKWorkout​Session)

Resumes the provided workout session.

func end(HKWorkout​Session)

Ends a workout session for the current app.

Notifications

static let HKUser​Preferences​Did​Change:​ NSNotification.Name

Notifies observers whenever the user changes his or her preferred units.

Relationships

Inherits From