predicateForWorkouts(operatorType:quantityType:maximumQuantity:)
Returns a predicate for matching workout activities based the maximum value of an associated quantity type.
Declaration
class func predicateForWorkouts(operatorType: NSComparisonPredicate.Operator, quantityType: HKQuantityType, maximumQuantity: HKQuantity) -> NSPredicateParameters
- operatorType:
The operator type to use when comparing the maximum quantity.
- quantityType:
The type of Hkquantitysample objects used to calculate the maximum quantity.
- maximumQuantity:
The target value for the maximum quantity.
Discussion
Use this convenience method to create a predicate that matches workouts with the specified maximum 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 maximum 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,
maximumQuantity: expectedQuantity)
}See Also
Creating workout predicates
predicateForObjects(from:)predicateForWorkouts(with:)predicateForWorkouts(activityPredicate:)predicateForWorkouts(with:duration:)predicateForWorkouts(operatorType:quantityType:averageQuantity:)predicateForWorkouts(operatorType:quantityType:minimumQuantity:)predicateForWorkouts(operatorType:quantityType:sumQuantity:)predicateForWorkouts(with:totalDistance:)predicateForWorkouts(with:totalEnergyBurned:)predicateForWorkouts(with:totalFlightsClimbed:)predicateForWorkouts(with:totalSwimmingStrokeCount:)