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

# init(heartbeatSeries:dataHandler:)

Creates a new heartbeat series query.

```
init(heartbeatSeries: HKHeartbeatSeriesSample, dataHandler: @escaping @Sendable (HKHeartbeatSeriesQuery, TimeInterval, Bool, Bool, (any Error)?) -> Void)
```

## Parameters

`heartbeatSeries`

The series sample containing the heartbeat data.

`dataHandler`

The handler called by the query. The handler takes the following parameters:

- `query`: The query that returned the heartbeat data.
- `timeSinceSeriesStart`: The time of the heartbeat, measured from the series builder’s start date. This must be a positive value.
- `precededByGap`: A Boolean value that indicates whether this heartbeat was immediately preceded by a gap in the data, indicating that one or more heartbeats may be missing.
- `done`: A Boolean value that indicates whether the query is complete.
- `error`: If an error occurred, this contains an object that describes the error; otherwise, `nil`.

## Discussion

The system calls the `dataHandler` once for each heartbeat until either the `done` parameter is <doc://com.apple.documentation/documentation/Foundation/NSExpression/true>, or you call [`stop(_:)`](/documentation/HealthKit/HKHealthStore/stop(_:)).

---

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)