<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKCorrelation",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKCorrelation"
  },
  "title" : "HKCorrelation"
}
-->

# HKCorrelation

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

```
class HKCorrelation
```

## 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`](/documentation/HealthKit/HKQuantityTypeIdentifier/dietaryEnergyConsumed) sample. You can also add nutritional quantity samples for any other items you want to track. Use the [`HKMetadataKeyFoodType`](/documentation/HealthKit/HKMetadataKeyFoodType) key to indicate the food’s name.

The [`HKCorrelation`](/documentation/HealthKit/HKCorrelation) class is a concrete subclass of the [`HKSample`](/documentation/HealthKit/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`](/documentation/HealthKit/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:)`](/documentation/HealthKit/HKCorrelation/init(type:start:end:objects:metadata:)) method.

## Topics

### Creating Correlations

[`+  correlationWithType:startDate:endDate:objects:`](/documentation/HealthKit/HKCorrelation/init(type:start:end:objects:))

Instantiates and returns a new correlation instance.

[`+  correlationWithType:startDate:endDate:objects:metadata:`](/documentation/HealthKit/HKCorrelation/init(type:start:end:objects:metadata:))

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

[`+  correlationWithType:startDate:endDate:objects:device:metadata:`](/documentation/HealthKit/HKCorrelation/init(type:start:end:objects:device:metadata:))

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

### Getting Correlation Data

[`correlationType`](/documentation/HealthKit/HKCorrelation/correlationType)

The type for this correlation.

[`objects`](/documentation/HealthKit/HKCorrelation/objects)

The set of sample objects that make up the correlation.

[`-  objectsForType:`](/documentation/HealthKit/HKCorrelation/objects(for:))

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

### Specifying Predicate Key Paths

[`HKPredicateKeyPathCorrelation`](/documentation/HealthKit/HKPredicateKeyPathCorrelation)

The key path for accessing the object’s correlation inside a predicate format string.

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Sendable`](/documentation/Swift/Sendable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

[`HKSample`](/documentation/HealthKit/HKSample)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)