Create and save health and fitness samples.


Most health and fitness data is saved to the HealthKit store using an HKSample subclass. All sample subclasses record information at a specified time. If the sample’s startDate and endDate properties are the same, the sample represents a point in time. If the endDate is after the startDate, the sample represents a time interval.

HealthKit uses different HKSample subclasses to store different types of data:

  • HKQuantitySample objects store quantities—a numerical value and units. Most HealthKit data types use quantity samples. For example, height, heart rate, and dietary energy consumed all use quantity samples.

  • HKCategorySample objects store a single option selected from a short list. For example, sleep data is recorded using category samples (the user can be in bed, asleep, or awake).

  • HKCorrelation samples combine two or more samples into a single value. For example, food and bloodpressure are represented using correlation samples. A food sample contains any number of nutrition samples, while a bloodpressure sample contains both a systolic and a diastolic sample.

  • HealthKit also uses other sample subclasses to represent more-specialized data types. For example, HKCDADocumentSample, HKWorkoutRoute, and HKWorkout.



Saving Data to HealthKit

Create and share HealthKit samples.

Reading and Writing HealthKit Series Data

Share and read heartbeat and quantity series data using series builders and queries.

Basic Samples

class HKCumulativeQuantitySample

A sample that represents a cumulative quantity.

class HKDiscreteQuantitySample

A sample that represents a discrete quantity.

class HKQuantitySample

A sample that represents a quantity, including the value and the units.

class HKCategorySample

A sample whose values are selected from a short list of possible values.

class HKCorrelation

A sample that groups multiple related samples into a single entry.

Units and Quantities

Objects used to specify a quantity for a given unit (for example, 175 lbs), and to convert between units (79.4 kg).

Metadata Keys

Constants used to add metadata to objects stored in HealthKit.

Series Data

class HKQuantitySeriesSampleBuilder

A builder object for incrementally building a sample that contains multiple quantities.

class HKHeartbeatSeriesBuilder

A builder object for incrementally building a heartbeat series.

class HKHeartbeatSeriesSample

A sample that represents a series of heartbeats.


class HKAudiogramSample

A sample that stores an audiogram.

class HKAudiogramSensitivityPoint

A hearing sensitivity reading associated with a hearing test.

Medical Records

Accessing Health Records

Read clinical record data from the HealthKit store.

Accessing Sample Data in the Simulator

Set up sample accounts to build and test your app.

Accessing a User’s Clinical Records

Display a user’s clinical records by requesting authorization and querying HealthKit for the records.

class HKClinicalRecord

A sample that stores a clinical record.

class HKFHIRResource

An object containing Fast Healthcare Interoperability Resources (FHIR) data.

class HKCDADocumentSample

A Clinical Document Architecture (CDA) sample that stores a single document.

class HKDocumentSample

An abstract class that represents a health document in the HealthKit store.

static let CDA: HKDocumentTypeIdentifier

The CDA Document type identifier, used when requesting permission to read or share CDA documents.

class HKDocumentType

A sample type used to create queries for documents.

Digital Signatures

Adding Digital Signatures

Cryptographically sign samples.

Abstract Superclasses

class HKQuantitySample

A sample that represents a quantity, including the value and the units.

class HKSample

A HealthKit sample represents a piece of data associated with a start and end time.

class HKObject

A piece of data that can be stored inside the HealthKit store.

Deprecated Classes

class HKCumulativeQuantitySeriesSample

A sample representing a series of cumulative quantity values.


See Also

Health Data

Saving Data to HealthKit

Create and share HealthKit samples.

Reading Data from HealthKit

Use queries to request sample data from HealthKit.

Data Types

Specify the kind of data used in HealthKit.


Query health and fitness data.