Type Method

predicateForWorkoutsWithOperatorType:totalEnergyBurned:

Returns a predicate for matching workouts based on the total energy burned.

Declaration

+ (NSPredicate *)predicateForWorkoutsWithOperatorType:(NSPredicateOperatorType)operatorType totalEnergyBurned:(HKQuantity *)totalEnergyBurned;

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
HKQuantity *energyBurned =
[HKQuantity quantityWithUnit:[HKUnit kilocalorieUnit] doubleValue:500];
 
NSPredicate *workout =
    [HKQuery predicateForWorkoutsWithOperatorType:
     NSGreaterThanOrEqualToPredicateOperatorType
     totalEnergyBurned:energyBurned];
 
NSPredicate *explicitWorkout =
[NSPredicate predicateWithFormat:@"%K >= %@",
 HKPredicateKeyPathWorkoutTotalEnergyBurned,
 energyBurned];

See Also

Creating Workout Predicates

+ predicateForObjectsFromWorkout:

Returns a predicate that matches any objects that have been associated with the provided workout.

+ predicateForWorkoutsWithOperatorType:duration:

Returns a predicate for matching workouts based on their duration.

+ predicateForWorkoutsWithOperatorType:totalDistance:

Returns a predicate for matching workouts based on the total distance traveled.

+ predicateForWorkoutsWithOperatorType:totalFlightsClimbed:

Returns a predicate that matches workout samples based on the number of flights climbed.

+ predicateForWorkoutsWithOperatorType:totalSwimmingStrokeCount:

Returns a predicate that matches workout samples based on the number of strokes while swimming.

+ predicateForWorkoutsWithWorkoutActivityType:

Returns a predicate for matching workouts based on the type of activity.