Contents

HKElectrocardiogramQuery

A query that returns the underlying voltage measurements for an electrocardiogram sample.

Declaration

class HKElectrocardiogramQuery

Overview

Use the HKElectrocardiogramQuery query to access the individual voltage measurements associated with an HKElectrocardiogram sample.

// Create a query for the voltage measurements
let voltageQuery = HKElectrocardiogramQuery(ecgSample) { (query, result) in
    switch(result) {
    
    case .measurement(let measurement):
        if let voltageQuantity = measurement.quantity(for: .appleWatchSimilarToLeadI) {
            // Do something with the voltage quantity here.

        }
    
    case .done:
        // No more voltages. Finish processing the existing voltages.

    case .error(let error):
        // Handle the error here.

    }
}

// Execute the query.
healthStore.execute(voltageQuery)

The query calls the data handler once for each voltage measurement, passing a HKElectrocardiogramQuery.Result.measurement(_:) instance that contains the voltage data. After it has sent all the voltage measurements, the query calls the data handler one last time, passing HKElectrocardiogramQuery.Result.done. If an error occurs, it stops collecting voltage data and passes HKElectrocardiogramQuery.Result.error(_:) instead.

Electrocardiogram queries are immutable: You set query’s properties when you create it, and they don’t change.

Topics

Creating the Query

Accessing the Results

See Also

Series queries