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


class HKStatisticsCollection : NSObject


For more information on statistics objects, see HKStatistics. For more information on calculating statistics over consecutive time intervals, see HKStatisticsCollectionQuery.


Accessing Statistics Collections

func statistics() -> [HKStatistics]

Returns an array of statistics objects representing the populated time intervals covered by the statistics collection query.

func statistics(for: Date) -> HKStatistics?

Returns the statistics object for the time interval that contains the provided date.

func enumerateStatistics(from: Date, to: Date, with: (HKStatistics, UnsafeMutablePointer<ObjCBool>) -> Void)

Enumerates the statistics objects for all the time intervals from the start date until the end date.

Getting Information About Statistics Collections

func sources() -> Set<HKSource>

Returns a set containing all the sources that had samples matched by the statistics collection query.


Inherits From

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.

struct HKStatisticsOptions

Options for specifying the statistic to calculate.