Contents

predicateForWorkouts(operatorType:quantityType:minimumQuantity:)

Returns a predicate for matching workout activities based the minimum value of an associated quantity type.

Declaration

class func predicateForWorkouts(operatorType: NSComparisonPredicate.Operator, quantityType: HKQuantityType, minimumQuantity: HKQuantity) -> NSPredicate

Parameters

  • operatorType:

    The operator type to use when comparing the minimum quantity.

  • quantityType:

    The type of Hkquantitysample objects used to calculate the minimum quantity.

  • minimumQuantity:

    The target value for the minimum quantity.

Discussion

Use this convenience method to create a predicate that matches workouts with the specified minimum quantity. For more information on how HealthKit calculates statistics for HKWorkoutActivity objects, see statistics(for:).

The following sample creates a predicate for workout activities with a minimum heart rate of 150 bmp or higher.

let quantityType = HKQuantityType(.heartRate)

let expectedQuantity =
HKQuantity(unit: .count().unitDivided(by: .minute()),
           doubleValue: 150.0)

let heartRatePredicate = HKQuery.predicateForWorkouts(
    operatorType: .greaterThanOrEqualTo,
    quantityType: quantityType,
    minimumQuantity: expectedQuantity)

See Also

Creating workout predicates