Samples

Create and save health and fitness samples.

Overview

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.

Topics

First Steps

Saving Data to HealthKit

Create and share HealthKit samples.

HKQuantitySample

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

HKCategorySample

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

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.

Quantity Series

HKQuantitySeriesSampleBuilder

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

Heartbeat Series

HKHeartbeatSeriesBuilder

A builder object for incrementally building a heartbeat series.

Beta
HKHeartbeatSeriesSample

A sample that represents a series of heartbeats.

Beta

Audiograms

HKAudiogramSample

A sample that stores an audiogram.

Beta
HKAudiogramSensitivityPoint

A hearing sensitivity reading associated with a hearing test.

Beta

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.

HKClinicalRecord

A sample that stores a clinical record.

HKFHIRResource

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

HKCDADocumentSample

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

HKDocumentSample

The HKDocumentSample class is an abstract class that represents a health document in the HealthKit store.

HKDocumentTypeIdentifierCDA

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

HKDocumentType

The HKDocumentType class is a concrete subclass of the HKSampleType class, used when creating queries for documents.

Digital Signatures

Adding Digital Signatures

Cryptographically sign samples.

Abstract Superclasses

HKQuantitySample

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

HKSample

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

HKObject

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

Deprecated Classes

HKCumulativeQuantitySeriesSample

A sample representing a series of cumulative quantity values.

Deprecated

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.

Queries

Query health and fitness data.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software