Class

HKHealthStore

The access point for all data managed by HealthKit.

Overview

Use a HKHealthStore 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.

For more information, see Setting Up HealthKit.

Topics

Accessing HealthKit

func authorizationStatus(for: HKObjectType) -> HKAuthorizationStatus

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

enum HKAuthorizationStatus

Constants indicating the authorization status for a particular data type.

enum HKAuthorizationRequestStatus

Values that indicate whether your app needs to request authorization from the user.

class func isHealthDataAvailable() -> Bool

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

func handleAuthorizationForExtension(completion: (Bool, Error?) -> Void)

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

Reading Characteristic Data

func biologicalSex() -> HKBiologicalSexObject

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

func bloodType() -> HKBloodTypeObject

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

func dateOfBirth() -> Date

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

Deprecated
func dateOfBirthComponents() -> DateComponents

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

func fitzpatrickSkinType() -> HKFitzpatrickSkinTypeObject

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

func wheelchairUse() -> HKWheelchairUseObject

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

Working with HealthKit Objects

func delete(HKObject, withCompletion: (Bool, Error?) -> Void)

Deletes the specified object from the HealthKit store.

func delete([HKObject], withCompletion: (Bool, Error?) -> Void)

Deletes the specified objects from the HealthKit store.

func deleteObjects(of: HKObjectType, predicate: NSPredicate, withCompletion: (Bool, Int, Error?) -> Void)

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

func earliestPermittedSampleDate() -> Date

Returns the earliest date permitted for samples.

func save(HKObject, withCompletion: (Bool, Error?) -> Void)

Saves the provided object to the HealthKit store.

func save([HKObject], withCompletion: (Bool, Error?) -> Void)

Saves an array of objects to the HealthKit store.

Managing Workouts

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

Associates the provided samples with the specified workout.

func splitTotalEnergy(HKQuantity, start: Date, end: Date, resultsHandler: (HKQuantity?, HKQuantity?, Error?) -> Void)

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

Deprecated

Querying HealthKit Data

func execute(HKQuery)

Starts executing the provided query.

func stop(HKQuery)

Stops a long-running query.

Accessing the Preferred Units

static let HKUserPreferencesDidChange: NSNotification.Name

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

Managing Background Delivery

enum HKUpdateFrequency

Constants that determine how often the system will launch your app in response to changes to HealthKit data.

func disableBackgroundDelivery(for: HKObjectType, withCompletion: (Bool, Error?) -> Void)

Disables background deliveries of update notifications for the specified data type.

func disableAllBackgroundDelivery(completion: (Bool, Error?) -> Void)

Disables all background deliveries of update notifications.

Managing Workout Sessions

func startWatchApp(with: HKWorkoutConfiguration, completion: (Bool, Error?) -> Void)

Launches or wakes the Watch app to create a new workout session.

func start(HKWorkoutSession)

Starts a workout session for the current app.

Deprecated
func pause(HKWorkoutSession)

Pauses the provided workout session.

Deprecated
func resumeWorkoutSession(HKWorkoutSession)

Resumes the provided workout session.

Deprecated
func end(HKWorkoutSession)

Ends a workout session for the current app.

Deprecated

Notifications

static let HKUserPreferencesDidChange: NSNotification.Name

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

Relationships

Inherits From

Conforms To

See Also

First Steps

About the HealthKit Framework

Learn about the architecture and design of the HealthKit framework.

Setting Up HealthKit

Set up and configure your HealthKit store.

Protecting User Privacy

Respect and safeguard your user’s privacy.