Type Method

predicateForWorkoutsWithOperatorType:duration:

Returns a predicate for matching workouts based on their duration.

Declaration

+ (NSPredicate *)predicateForWorkoutsWithOperatorType:(NSPredicateOperatorType)operatorType duration:(NSTimeInterval)duration;

Parameters

operatorType

The operator type to use when comparing the duration.

duration

The target duration.

Return Value

A predicate for matching workouts based on their duration. This predicate works only on workouts.

Discussion

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

// Predicate matching workouts equal to or longer than 30 minutes
NSPredicate *workout =
    [HKQuery predicateForWorkoutsWithOperatorType:
 
     NSGreaterThanOrEqualToPredicateOperatorType
      duration:60.0 * 30.0];
 
NSPredicate *explicitWorkout =
[NSPredicate predicateWithFormat:@"%K >= %d",
 HKPredicateKeyPathWorkoutDuration,
 60 * 30];

See Also

Creating Workout Predicates

+ predicateForObjectsFromWorkout:

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

+ predicateForWorkoutsWithOperatorType:totalDistance:

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

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