HKHeartbeatSeriesQueryDescriptor
A query interface that reads the heartbeat series data stored in a heartbeat sample using Swift concurrency.
Declaration
struct HKHeartbeatSeriesQueryDescriptorOverview
Use HKHeartbeatSeriesQueryDescriptor to read the heartbeat data included in a HKHeartbeatSeriesSample. To read the individual heartbeats, create a heartbeat series query descriptor using the desired series sample, and then call the results(for:) method on the descriptor.
// Create the descriptor.
let heartbeatDescriptor = HKHeartbeatSeriesQueryDescriptor(myHeartbeatSample)
// Get the AsyncSequence that returns individual heartbeats.
let series = heartbeatDescriptor.results(for: store)
// Access the data for each haeartbeat.
for try await heartbeat in series {
// Process the results here.
print(heartbeat.precededByGap)
print(heartbeat.timeIntervalSinceStart)
}While this method returns an AsyncSequence, unlike the long-running queries, this sequence has a finite size. Iterating over the sequence asynchronously returns heartbeat data, automatically terminating after you receive all the data.