Contents

statistics(for:)

Returns the activity’s statistics for the provided quantity type.

Declaration

func statistics(for quantityType: HKQuantityType) -> HKStatistics?

Parameters

  • quantityType:

    The type of Hkquantitysample objects used to calculate the statistics.

Discussion

HealthKit calculates an HKStatistics object based on the HKQuantitySample objects that meet the following requirements:

  • Match the specified HKQuantityType.

  • Are associated with the containing workout.

  • Fall within the activity’s time frame.

Furthermore, if a quantity sample extends beyond the activity’s time frame, HealthKit interpolates a quantity value to represent the portion within the time frame, and uses that value instead.

If there are no matching quantity values, this method returns nil.

See Also

Accessing workout data