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

# init(electrocardiogram:dataHandler:)

Creates a new electrocardiogram query object.

```
init(electrocardiogram: HKElectrocardiogram, dataHandler: @escaping (HKElectrocardiogramQuery, HKElectrocardiogram.VoltageMeasurement?, Bool, (any Error)?) -> Void)
```

## Parameters

`electrocardiogram`

The electrocardiogram sample whose voltages you want to access.

`dataHandler`

A block that the query calls repeatedly to return the voltage data. The handler takes the following parameters:

- `query`: The query that returned the results.
- `voltageMeasurement`: A voltage measurement.
- `done`: Indicates whether the query has additional voltage measurements to send.
- `error`: If an error occurred, this parameter contains information about the error. Otherwise it’s `nil`.

## Discussion

When you run the query, it calls the data handler once for each voltage measurement, passing the voltage data. On the last voltage measurement, it sets the `done` parameter to <doc://com.apple.documentation/documentation/Swift/true>. If an error occurs, it stops collecting voltage data and calls the data handler; it sets the `voltageMeasurement` parameter to `nil`, and passes in an <doc://com.apple.documentation/documentation/Foundation/NSError> object that describes the error.

---

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)