Enumeration

HKStatisticsOptions

Options for specifying the statistic to calculate.

Declaration

typedef enum HKStatisticsOptions : NSUInteger {
    ...
} 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 HKStatisticsOptionSeparateBySource option with any of the other options.

HKQuantityType *cumulativeActiveEnergyBurned =
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned];
 
HKQuantityType *discreteHeartRate =
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
 
// Cannot combine cumulative options with discrete options.
// However, you can combine a cumulative option and seperated by source
HKStatisticsQuery *cumulativeQuery =
[[HKStatisticsQuery alloc]
 initWithQuantityType:cumulativeActiveEnergyBurned
 quantitySamplePredicate:nil
 options:HKStatisticsOptionCumulativeSum | HKStatisticsOptionSeparateBySource
 completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {
 
      // ... process the results here
 }];
 
// You can also combine any number of discrete options
// and the seperated by source option.
HKStatisticsQuery *discreteQuery =
[[HKStatisticsQuery alloc]
 initWithQuantityType:discreteHeartRate
 quantitySamplePredicate:nil
 options:HKStatisticsOptionDiscreteAverage | HKStatisticsOptionDiscreteMin |
 HKStatisticsOptionDiscreteMax | HKStatisticsOptionSeparateBySource
 completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {
 
     // ... process the results here
 }];

Topics

Constants

HKStatisticsOptionNone

An option indicating that the system will not calculate any statistics values.

HKStatisticsOptionSeparateBySource

An option indicating that the system calculates the specified statistics separately for each source.

HKStatisticsOptionDiscreteAverage

An option indicating that the system calculates the average quantity for the samples.

HKStatisticsOptionDiscreteMin

An option indicating that the system calculates the minimum quantity for the samples.

HKStatisticsOptionDiscreteMax

An option indicating that the system calculates the maximum quantity for the samples.

HKStatisticsOptionCumulativeSum

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

HKStatisticsOptionMostRecent

An option indicating that the system returns the most recent quantity from the matching samples.

HKStatisticsOptionDuration

An option indicating that the system calculates the total duration covering all the samples.

Deprecated Constants

HKStatisticsOptionDiscreteMostRecent

An option indicating that the system returns the most recent quantity from the matching samples.

Deprecated

See Also

Calculating Statistics

HKStatisticsQuery

A query that performs statistical calculations over a set of matching quantity samples, and returns the results.

HKStatisticsCollectionQuery

A query that performs multiple statistics queries over a series of fixed-length time intervals, and returns the results.

HKStatistics

An object that represents the result of calculating the minimum, maximum, average, or sum over a set of samples from the HealthKit store.

HKStatisticsCollection

An object that manages a collection of statistics; each statistics object represents the data calculated over a separate time interval.