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

# predicateForWorkouts(with:duration:)

Returns a predicate for matching workouts based on their duration.

```
class func predicateForWorkouts(with operatorType: NSComparisonPredicate.Operator, duration: TimeInterval) -> NSPredicate
```

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

```swift
// Predicate matching workouts equal to or longer than 30 minutes
let workout = HKQuery.predicateForWorkoutsWithOperatorType(
    .GreaterThanOrEqualToPredicateOperatorType,
    duration: 60.0 * 30.0)
 
 
let explicitWorkout = NSPredicate(format: "%K >= %d",
                                  HKPredicateKeyPathWorkoutDuration, 60 * 30)
```

## See Also

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

The key path for accessing the workout’s duration.

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

The workout’s duration.



---

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)