Type Method

predicateForWorkoutsWithOperatorType:totalDistance:

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

Declaration

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

Parameters

operatorType

The operator type to use when comparing the total distance.

totalDistance

The target distance.

Return Value

A predicate for matching workouts based on the total distance traveled. This predicate works only on workouts.

Discussion

Use this convenience method to create a predicate that matches against a workout’s total distance. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

// Predicate matching workouts covering 6.5 miles or more.
HKQuantity *distance =
    [HKQuantity quantityWithUnit:[HKUnit mileUnit] doubleValue:6.5];
 
NSPredicate *workout =
    [HKQuery predicateForWorkoutsWithOperatorType:
     NSGreaterThanOrEqualToPredicateOperatorType
     totalDistance:distance];
 
NSPredicate *explicitWorkout =
[NSPredicate predicateWithFormat:@"%K >= %@",
 HKPredicateKeyPathWorkoutTotalDistance,
 distance];

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:totalEnergyBurned:

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

+ 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.