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.

Declaration

@interface HKStatistics : NSObject

Overview

HealthKit creates statistic objects using either a statistics query or a statistics collection query. For the statistics query, it performs the specified calculations over all the samples that match the query. For the statistics collection query, it partitions the matching samples into a set of time intervals and performs the calculations over each interval separately.

By default, these queries automatically merge the data from all of your data sources before performing the calculations. If you want to merge the data yourself, you can set the HKStatisticsOptionSeparateBySource option. You can then request the statistical data for each source separately.

When requesting data from a statistics object, your request must match the options you used when creating the query. For example, if you create a query using the HKStatisticsOptionDiscreteAverage option, you must access the results using the averageQuantity method.

For more information on calculating statistical data, see HKStatisticsQuery Class Reference. To calculate the statistics over a series of time intervals, see the HKStatisticsCollectionQuery Class Reference.

Topics

Getting Property Data

startDate

The start of the time period included in these statistics.

endDate

The end of the time period included in these statistics.

quantityType

The quantity type of the samples used to calculate these statistics.

sources

An array containing all the sources contributing to these statistics.

Getting Statistics Data

- averageQuantity

Returns the average value from all the samples that match the query.

- averageQuantityForSource:

Returns the average value from all the samples that match the query and that were created by the specified source.

- maximumQuantity

Returns the maximum value from all the samples that match the query.

- maximumQuantityForSource:

Returns the maximum value from all the samples that match the query and that were created by the specified source.

- minimumQuantity

Returns the minimum value from all the samples that match the query.

- minimumQuantityForSource:

Returns the minimum value from all the samples that match the query and that were created by the specified source.

- sumQuantity

Returns the sum of all the samples that match the query.

- sumQuantityForSource:

Returns the sum of all the samples that match the query and that were created by the specified source.

- duration

Returns the total duration covering all the samples that match the query.

Beta
- durationForSource:

Returns the total duration covering all the samples created by the specified source that also match the query.

Beta

Getting the Most Recent Quantity

- mostRecentQuantity

Returns the most recent value from all the samples that match the query.

- mostRecentQuantityForSource:

Returns the most recent value from all the samples that match the query and were created by the specified source.

- mostRecentQuantityDateInterval

Returns the date interval of the most recent sample that matches the query.

- mostRecentQuantityDateIntervalForSource:

Returns the date interval of the most recent sample that matches the query and was created by the specified source.

Relationships

Inherits From

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.

HKStatisticsCollection

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

HKStatisticsOptions

Options for specifying the statistic to calculate.

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