HKHealthStore

class HKHealthStore : NSObject
  • Convenience method to retrieve the latest sample of a given type.

    Declaration

    Swift

    public func c3_latestSample(ofType type: HKQuantityTypeIdentifier, callback: @escaping ((HKQuantity?, Error?) -> Void))

    Parameters

    type

    The type of samples to retrieve

    callback

    Callback to call when query finishes, comes back either with a quantity, an error or neither

  • Convenience method to retrieve samples from a given period. Orders by end date, descending. Don’t use this to get a total over a given period, use c3_summaryOfSamplesOfTypeBetween() (which is using HKStatisticsCollectionQuery).

    Declaration

    Swift

    public func c3_samplesOfTypeBetween(_ typeIdentifier: HKQuantityTypeIdentifier, start: Date, end: Date, limit: Int, callback: @escaping ((_ results: [HKQuantitySample]?, _ error: Error?) -> Void))

    Parameters

    typeIdentifier

    The type of samples to retrieve

    start

    Start date

    end

    End date

    limit

    How many samples to retrieve at max

    callback

    Callback to call when query finishes, comes back either with an array of samples, an error or neither

  • Retrieve a quantity summed over a given period. Uses HKStatisticsCollectionQuery, the callback will be called on a background queue.

    Declaration

    Swift

    public func c3_summaryOfSamplesOfTypeBetween(_ typeIdentifier: HKQuantityTypeIdentifier, start: Date, end: Date, callback: @escaping ((_ result: HKQuantitySample?, _ error: Error?) -> Void))

    Parameters

    typeIdentifier

    The type of samples to retrieve

    start

    Start date

    end

    End date

    callback

    Callback to call, on a background queue, when the query finishes, containing one HKQuantitySample spanning the whole period or an error (or neither)