Structure

HKStatisticsOptions

Options for specifying which statistics to calculate.

Overview

You cannot combine a discrete option with a cumulative option. You can, however, combine multiple discrete options together to perform multiple calculations. You can also combine the separateBySource option with any of the other options.

let cumulativeActiveEnergyBurned =
    HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)
 
let discreteHeartRate =
    HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)
 
// Cannot combine cumulative options with discrete options.
// However, you can combine a cumulative option and seperated by source
let cumulativeQuery = HKStatisticsQuery(quantityType:cumulativeActiveEnergyBurned,
                                        quantitySamplePredicate:nil,
                                        options: .CumulativeSum | .SeparateBySource) {
                                            query, statistics, error in
                                            
                                            // ... process the results here
}
 
// You can also combine any number of discrete options
// and the seperated by source option.
let discreteQuery = HKStatisticsQuery(quantityType: discreteHeartRate,
                                      quantitySamplePredicate: nil,
                                      options: .DiscreteAverage | .DiscreteMin |
                                        .DiscreteMax | .SeparateBySource) {
                                            query, statistics, error in
                                            
                                            // ... process the results here
}

Topics

Constants

static var separateBySource: HKStatisticsOptions

An option indicating that the specified statistics will be calculated separately for each source.

static var discreteAverage: HKStatisticsOptions

An option indicating that the system will calculate the average quantity for the samples.

static var discreteMin: HKStatisticsOptions

An option indicating that the system will calculate the minimum quantity for the samples.

static var discreteMax: HKStatisticsOptions

An option indicating that the system will calculate the maximum quantity for the samples.

static var cumulativeSum: HKStatisticsOptions

An option indicating that the system will calculate the sum of all the quantities for the samples.