Class

HKCorrelation

The HKCorrelation class is a concrete subclass of the HKSample class. Use a correlation object to group multiple samples into a single data entry. HealthKit uses correlations to represent both blood pressure and food. Blood pressure correlations always include two quantity samples that represent the systolic and diastolic values. In contrast, food correlations can contain a wide range of dietary information about the food, including information about the fat, protein, carbohydrates, energy, and vitamins consumed.

Overview

Correlations are immutable: You set the correlation’s properties when the object is first created, and they cannot change.

Subclassing Notes

Like many HealthKit classes, the HKCorrelation class should not be subclassed. You can extend the correlation class by adding metadata with custom keys as appropriate for your app. For more information, see the init(type:start:end:objects:metadata:) method.

Topics

Creating Correlations

init(type: HKCorrelationType, start: Date, end: Date, objects: Set<HKSample>)

Instantiates and returns a new correlation instance.

init(type: HKCorrelationType, start: Date, end: Date, objects: Set<HKSample>, metadata: [String : Any]?)

Instantiates and returns a new correlation instance with the provided metadata.

init(type: HKCorrelationType, start: Date, end: Date, objects: Set<HKSample>, device: HKDevice?, metadata: [String : Any]?)

Instantiates and returns a new correlation instance with the provided device and metadata.

Getting Correlation Data

var correlationType: HKCorrelationType

The type for this correlation.

var objects: Set<HKSample>

The set of HKSample objects that make up the correlation.

func objects(for: HKObjectType)

Returns a set containing all the objects of the specified type in the correlation.

Relationships

Inherits From

Conforms To