Class

HKSample

A HealthKit sample represents a piece of data associated with a start and end time. 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.

Overview

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.

Subclassing Notes

Like many HealthKit classes, the HKSample class should not be subclassed. You can extend HKSample and its subclasses by adding custom metadata keys and values to the metadata dictionary when the object is created.

Topics

Accessing the Sample’s Data

var startDate: Date

The sample’s start date.

var endDate: Date

The sample’s end date.

Constants

Sort Identifiers

Constants that can be used to sort samples.

Predicate Key Paths

Constants that can be used to create predicate format strings.

Relationships

Inherits From

Conforms To