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

# HKElectrocardiogram

A sample for electrocardiogram data.

```
class HKElectrocardiogram
```

## Overview

An [`HKElectrocardiogram`](/documentation/HealthKit/HKElectrocardiogram) is a collection of voltage values representing waveforms from one or more leads. The [`HKElectrocardiogram`](/documentation/HealthKit/HKElectrocardiogram) sample provides high-level details about the ECG reading, such as the sampling frequency or classification. HealthKit provides read-only access to electrocardiogram (ECG) data saved by Apple Watch.

You can query for [`HKElectrocardiogram`](/documentation/HealthKit/HKElectrocardiogram) samples using an [`HKSampleQuery`](/documentation/HealthKit/HKSampleQuery).

```swift
// Create the electrocardiogram sample type.
let ecgType = HKObjectType.electrocardiogramType()


// Query for electrocardiogram samples
let ecgQuery = HKSampleQuery(sampleType: ecgType,
                             predicate: nil,
                             limit: HKObjectQueryNoLimit,
                             sortDescriptors: nil) { (query, samples, error) in
    if let error = error {
        // Handle the error here.
        fatalError("*** An error occurred \(error.localizedDescription) ***")
    }
    
    guard let ecgSamples = samples as? [HKElectrocardiogram] else {
        fatalError("*** Unable to convert \(String(describing: samples)) to [HKElectrocardiogram] ***")
    }
    
    for sample in ecgSamples {
        // Handle the samples here.
        
    }
}

// Execute the query.
healthStore.execute(ecgQuery)
```

After retrieving an [`HKElectrocardiogram`](/documentation/HealthKit/HKElectrocardiogram) sample, you can access the voltage measurements associated with the sample use an [`HKElectrocardiogramQuery`](/documentation/HealthKit/HKElectrocardiogramQuery) query.

```swift
// Create a query for the voltage measurements
let voltageQuery = HKElectrocardiogramQuery(ecgSample) { (query, result) in
    switch(result) {
    
    case .measurement(let measurement):
        if let voltageQuantity = measurement.quantity(for: .appleWatchSimilarToLeadI) {
            // Do something with the voltage quantity here.

        }
    
    case .done:
        // No more voltage measurements. Finish processing the existing measurements.

    case .error(let error):
        // Handle the error here.

    }
}

// Execute the query.
healthStore.execute(voltageQuery)
```

## Topics

### Accessing Overview Information

[`classification`](/documentation/HealthKit/HKElectrocardiogram/classification-swift.property)

The ECG’s classification.

[`HKElectrocardiogram.Classification`](/documentation/HealthKit/HKElectrocardiogram/Classification-swift.enum)

Classifications returned by Apple Watch’s ECG algorithm.

[`averageHeartRate`](/documentation/HealthKit/HKElectrocardiogram/averageHeartRate)

The user’s average heart rate during the ECG.

[`symptomsStatus`](/documentation/HealthKit/HKElectrocardiogram/symptomsStatus-swift.property)

A value that indicates whether the user entered a symptom when they recorded the ECG.

[`HKElectrocardiogram.SymptomsStatus`](/documentation/HealthKit/HKElectrocardiogram/SymptomsStatus-swift.enum)

Values indicating whether the user entered a symptom when they recorded the ECG.

### Accessing Voltage Measurements

[`numberOfVoltageMeasurements`](/documentation/HealthKit/HKElectrocardiogram/numberOfVoltageMeasurements)

The number of voltage measurements associated with this sample.

[`samplingFrequency`](/documentation/HealthKit/HKElectrocardiogram/samplingFrequency)

The frequency at which the Apple Watch sampled the voltage.

[`HKElectrocardiogram.VoltageMeasurement`](/documentation/HealthKit/HKElectrocardiogram/VoltageMeasurement)

The voltage for all leads at a single point in time.

[`HKElectrocardiogram.Lead`](/documentation/HealthKit/HKElectrocardiogram/Lead)

The lead used to record a voltage measurement.

### Specifying Metadata

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

A key for metadata indicating the version number of the algorithm Apple Watch uses to generate an ECG reading.

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

Version numbers for the algorithm Apple Watch uses to generate an ECG reading.

### Specifying Predicate Key Paths

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

The key path for the sample’s classification.

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

The key path for the sample’s symptom status.

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

The key path for the sample’s average heart rate.



---

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)