HKElectrocardiogramQueryDescriptor
A query interface that reads the underlying voltage measurements for an electrocardiogram sample using Swift concurrency.
Declaration
struct HKElectrocardiogramQueryDescriptorOverview
Use HKElectrocardiogramQueryDescriptor to access the individual voltage measurements associated with an HKElectrocardiogram sample. To read the individual voltage measurements, create an electrocardiogram query descriptor using the desired sample, and then call the results(for:) method on the descriptor.
// Create the descriptor.
let ecgDescriptor = HKElectrocardiogramQueryDescriptor(myElectrocardiogram)
// Get the AsyncSequence that returns individual voltage measurements.
let voltages = ecgDescriptor.results(for: store)
// Access each voltage measurement.
for try await measurement in voltages {
// Process the results here.
print(measurement.quantity(for: .appleWatchSimilarToLeadI) ?? "No Measurement")
print(measurement.timeSinceSampleStart)
}While this method returns an AsyncSequence, unlike the long-running queries, this sequence has a finite size. Iterating over the sequence asynchronously returns voltage measurements, automatically terminating after you receive all the measurements.