<!--
{
  "availability" : [
    "iOS: 8.0.0 - 27.0.0",
    "iPadOS: 8.0.0 - 27.0.0",
    "macCatalyst: 13.0.0 - 27.0.0",
    "macOS: 13.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 2.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKQuery/predicateForWorkouts(with:totalDistance:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuery(cm)predicateForWorkoutsWithOperatorType:totalDistance:"
  },
  "title" : "predicateForWorkouts(with:totalDistance:)"
}
-->

# predicateForWorkouts(with:totalDistance:)

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

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

```swift
// 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

[`totalDistance`](/documentation/HealthKit/HKWorkout/totalDistance)

The total distance traveled during the workout.

[`HKPredicateKeyPathWorkoutTotalDistance`](/documentation/HealthKit/HKPredicateKeyPathWorkoutTotalDistance)

The key path for accessing the workout’s total distance.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)