Type Method

predicateForWorkouts(with:)

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

Declaration

class func predicateForWorkouts(with workoutActivityType: HKWorkoutActivityType) -> NSPredicate

Parameters

workoutActivityType

The type of activity. For a list of valid workout activities, see HKWorkoutActivityType.

Return Value

A predicate for matching workouts based on the type of activity.

Discussion

Use this convenience method to create a predicate that matches workouts based on their activity. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

let workout = HKQuery.predicateForWorkoutsWithWorkoutActivityType(.Curling)
 
 
let explicitWorkout = NSPredicate(format: "%K == %d",
                                  HKPredicateKeyPathWorkoutType,
                                  HKWorkoutActivityType.Curling.rawValue)

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, totalDistance: HKQuantity) -> NSPredicate

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

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.