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

# predicateForWorkouts(with:totalSwimmingStrokeCount:)

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

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

## Parameters

`operatorType`

The operator to use when comparing the sample to the target number of flights climbed.

`totalSwimmingStrokeCount`

A quantity representing the target stroke count.

## Return Value

A predicate that matches workouts based on the number of strokes while swimming.

## Discussion

This convenience method creates a predicate that compares the number of swimming strokes during a workout with a target number. The following sample uses the convenience method and a predicate format string to create equivalent predicates.

```swift
// Creating a predicate using the convenience method.
let swimmingStrokeCount = HKQuantity(unit: HKUnit.count(), doubleValue: 500.0)
let longSwim = HKQuery.predicateForWorkouts(with: .greaterThanOrEqualTo, totalSwimmingStrokeCount: swimmingStrokeCount)

// Creating a predicate using a predicate format string.
let explicitLongSwim = NSPredicate(format: "%K >= %@",
                                   HKPredicateKeyPathWorkoutTotalSwimmingStrokeCount,
                                   swimmingStrokeCount)
```

## See Also

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

The key path for accessing the number of strokes during a swimming workout.



---

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)