---
title: HKElectrocardiogram
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkelectrocardiogram
---

# HKElectrocardiogram

A sample for electrocardiogram data.

## Declaration

```swift
class HKElectrocardiogram
```

## Overview

Overview An HKElectrocardiogram is a collection of voltage values representing waveforms from one or more leads. The 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 samples using an HKSampleQuery. // 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 sample, you can access the voltage measurements associated with the sample use an HKElectrocardiogramQuery query. // 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](healthkit/hkelectrocardiogram/classification-swift.property.md)
- [HKElectrocardiogram.Classification](healthkit/hkelectrocardiogram/classification-swift.enum.md)
- [averageHeartRate](healthkit/hkelectrocardiogram/averageheartrate.md)
- [symptomsStatus](healthkit/hkelectrocardiogram/symptomsstatus-swift.property.md)
- [HKElectrocardiogram.SymptomsStatus](healthkit/hkelectrocardiogram/symptomsstatus-swift.enum.md)

### Accessing Voltage Measurements

- [numberOfVoltageMeasurements](healthkit/hkelectrocardiogram/numberofvoltagemeasurements.md)
- [samplingFrequency](healthkit/hkelectrocardiogram/samplingfrequency.md)
- [HKElectrocardiogram.VoltageMeasurement](healthkit/hkelectrocardiogram/voltagemeasurement.md)
- [HKElectrocardiogram.Lead](healthkit/hkelectrocardiogram/lead.md)

### Specifying Metadata

- [HKMetadataKeyAppleECGAlgorithmVersion](healthkit/hkmetadatakeyappleecgalgorithmversion.md)
- [HKAppleECGAlgorithmVersion](healthkit/hkappleecgalgorithmversion.md)

### Specifying Predicate Key Paths

- [HKPredicateKeyPathECGClassification](healthkit/hkpredicatekeypathecgclassification.md)
- [HKPredicateKeyPathECGSymptomsStatus](healthkit/hkpredicatekeypathecgsymptomsstatus.md)
- [HKPredicateKeyPathAverageHeartRate](healthkit/hkpredicatekeypathaverageheartrate.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

### Electrocardiograms

- [HKElectrocardiogram.VoltageMeasurement](healthkit/hkelectrocardiogram/voltagemeasurement.md)
