Structure

HKStatisticsOptions

Options for specifying the statistic 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 discreteMostRecent: HKStatisticsOptions

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

Beta
static var cumulativeSum: HKStatisticsOptions

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

Initializers

init(rawValue: UInt)

Returns a newly initialized statistics option using the provided integer.

Relationships

Conforms To

See Also

Calculating Statistics

class HKStatisticsQuery

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

class HKStatisticsCollectionQuery

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

class HKStatistics

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

class HKStatisticsCollection

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

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software