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

# HKElectrocardiogramQuery

A query that returns the underlying voltage measurements for an electrocardiogram sample.

```
class HKElectrocardiogramQuery
```

## Overview

Use the [`HKElectrocardiogramQuery`](/documentation/HealthKit/HKElectrocardiogramQuery) query to access the individual voltage measurements associated with an [`HKElectrocardiogram`](/documentation/HealthKit/HKElectrocardiogram) sample.

```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 voltages. Finish processing the existing voltages.

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

    }
}

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

The query calls the data handler once for each voltage measurement, passing a [`HKElectrocardiogramQuery.Result.measurement(_:)`](/documentation/HealthKit/HKElectrocardiogramQuery/Result/measurement(_:)) instance that contains the voltage data. After it has sent all the voltage measurements, the query calls the data handler one last time, passing [`HKElectrocardiogramQuery.Result.done`](/documentation/HealthKit/HKElectrocardiogramQuery/Result/done). If an error occurs, it stops collecting voltage data and passes [`HKElectrocardiogramQuery.Result.error(_:)`](/documentation/HealthKit/HKElectrocardiogramQuery/Result/error(_:)) instead.

Electrocardiogram queries are immutable: You set query’s properties when you create it, and they don’t change.

## Topics

### Creating the Query

[`init(_:dataHandler:)`](/documentation/HealthKit/HKElectrocardiogramQuery/init(_:dataHandler:))

Creates a new electrocardiogram query object.

### Accessing the Results

[`HKElectrocardiogramQuery.Result`](/documentation/HealthKit/HKElectrocardiogramQuery/Result)

Partial results for an electrocardiogram query.

[`init(electrocardiogram:dataHandler:)`](/documentation/HealthKit/HKElectrocardiogramQuery/init(electrocardiogram:dataHandler:))

Creates a new electrocardiogram query object.



---

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)