Type Method

predicateForWorkouts(with:totalDistance:)

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

Declaration

class func predicateForWorkouts(with operatorType: NSComparisonPredicate.Operator, totalDistance: HKQuantity) -> NSPredicate

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.
let distance = HKQuantity(unit: HKUnit.mileUnit(), doubleValue: 6.5)
let workout = HKQuery.predicateForWorkoutsWithOperatorType(
    .GreaterThanOrEqualToPredicateOperatorType,
    totalDistance: distance)
 
 
let explicitWorkout = NSPredicate(format: "%K >= %@",
                                  HKPredicateKeyPathWorkoutTotalDistance, distance)

See Also

Creating Workout Predicates

class func predicateForObjects(from: HKWorkout) -> NSPredicate

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

class func predicateForWorkouts(with: NSComparisonPredicate.Operator, totalFlightsClimbed: HKQuantity) -> NSPredicate

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

class func predicateForWorkouts(with: NSComparisonPredicate.Operator, totalSwimmingStrokeCount: HKQuantity) -> NSPredicate

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

class func predicateForWorkouts(with: HKWorkoutActivityType) -> NSPredicate

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