---
title: HKCorrelation
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkcorrelation
---

# HKCorrelation

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

## Declaration

```swift
class HKCorrelation
```

## Mentioned in

About the HealthKit framework Saving data to HealthKit

## Overview

Overview HealthKit uses correlations to represent both blood pressure and food. Blood pressure correlations always include two quantity samples, representing the systolic and diastolic values. Food correlations can contain a wide range of dietary information about the food, including information about the fat, protein, carbohydrates, energy, and vitamins consumed. In general, a food correlation should include at least a dietaryEnergyConsumed sample. You can also add nutritional quantity samples for any other items you want to track. Use the HKMetadataKeyFoodType key to indicate the food’s name. The HKCorrelation class is a concrete subclass of the HKSample class. Correlations are immutable: You set the correlation’s properties when the object is first created, and they cannot change. Extend Correlation Samples As with many HealthKit classes, don’t subclass the HKCorrelation class. 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:start:end:objects:)](healthkit/hkcorrelation/init(type:start:end:objects:).md)
- [init(type:start:end:objects:metadata:)](healthkit/hkcorrelation/init(type:start:end:objects:metadata:).md)
- [init(type:start:end:objects:device:metadata:)](healthkit/hkcorrelation/init(type:start:end:objects:device:metadata:).md)

### Getting Correlation Data

- [correlationType](healthkit/hkcorrelation/correlationtype.md)
- [objects](healthkit/hkcorrelation/objects.md)
- [objects(for:)](healthkit/hkcorrelation/objects(for:).md)

### Specifying Predicate Key Paths

- [HKPredicateKeyPathCorrelation](healthkit/hkpredicatekeypathcorrelation.md)

### Initializers

- [init(type:startDate:endDate:objects:)](healthkit/hkcorrelation/init(type:startdate:enddate:objects:).md)
- [init(type:startDate:endDate:objects:device:metadata:)](healthkit/hkcorrelation/init(type:startdate:enddate:objects:device:metadata:).md)
- [init(type:startDate:endDate:objects:metadata:)](healthkit/hkcorrelation/init(type:startdate:enddate:objects:metadata:).md)

## Relationships

### Inherits From

- [HKSample](healthkit/hksample.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Basic samples

- [HKCumulativeQuantitySample](healthkit/hkcumulativequantitysample.md)
- [HKDiscreteQuantitySample](healthkit/hkdiscretequantitysample.md)
- [HKQuantitySample](healthkit/hkquantitysample.md)
- [HKCategorySample](healthkit/hkcategorysample.md)
- [Units and quantities](healthkit/units-and-quantities.md)
- [Metadata Keys](healthkit/metadata-keys.md)
