---
title: "init(electrocardiogram:dataHandler:)"
framework: healthkit
role: symbol
role_heading: Initializer
path: "healthkit/hkelectrocardiogramquery/init(electrocardiogram:datahandler:)"
---

# init(electrocardiogram:dataHandler:)

Creates a new electrocardiogram query object.

## Declaration

```swift
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:

## Discussion

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 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 NSError object that describes the error.

## See Also

### Accessing the Results

- [HKElectrocardiogramQuery.Result](healthkit/hkelectrocardiogramquery/result.md)
