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


class HKSample : HKObject


The HKSample class is an abstract class. You should never instantiate a HKSample object directly. Instead, you always work with one of its concrete subclasses: HKCategorySample, HKQuantitySample, HKCorrelation, or HKWorkout classes.

HealthKit samples are all immutable: You set the sample’s properties when you create it, and they cannot change.

If the sample represents data over a duration, the start time must be earlier than the end time. If the sample represents data at a particular instant, the start and end times can be the same.


Accessing the Sample’s Data

var startDate: Date

The sample’s start date.

var endDate: Date

The sample’s end date.

Sort Identifiers

let HKSampleSortIdentifierStartDate: String

A constant for sorting samples based on their start date.

let HKSampleSortIdentifierEndDate: String

A constant for sorting samples based on their end date.

Predicate Key Paths

let HKPredicateKeyPathStartDate: String

The key path for the sample’s start date.

let HKPredicateKeyPathEndDate: String

The key path for the sample’s end date.


Inherits From

Conforms To

See Also

Abstract Superclasses

class HKQuantitySample

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

class HKObject

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

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