Options for specifying the statistic to calculate.
SDKs
- iOS 8.0+
- Mac Catalyst 13.0+
- watchOS 2.0+
Framework
- Health
Kit
Declaration
struct HKStatisticsOptions
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 separate
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
}