Returns a predicate for matching workouts based on the total energy burned.
SDKs
- iOS 8.0+
- Mac Catalyst 13.0+
- watchOS 2.0+
Framework
- Health
Kit
Declaration
class func predicateForWorkouts(with operatorType: NSComparison Predicate.Operator, totalEnergyBurned: HKQuantity) -> NSPredicate
Parameters
operatorType
The operator type to use when comparing the total energy burned.
totalEnergyBurned
The target amount of energy burned.
Return Value
A predicate for matching workouts based on the total energy burned. This predicate works only on workouts.
Discussion
Use this convenience method to create a predicate that matches against a workout’s total energy burned. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.
// Predicate matching workouts burning 500 calories or more
let energyBurned = HKQuantity(unit: HKUnit.kilocalorieUnit(), doubleValue: 500)
let workout = HKQuery.predicateForWorkoutsWithOperatorType(
.GreaterThanOrEqualToPredicateOperatorType,
totalEnergyBurned: energyBurned)
let explicitWorkout = NSPredicate(format: "%K >= %@",
HKPredicateKeyPathWorkoutTotalEnergyBurned, energyBurned)