Contents

predicateForWorkoutActivities(operatorType:duration:)

Returns a predicate for matching workout activities based on their duration.

Declaration

class func predicateForWorkoutActivities(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 workout activities based on their duration. This predicate works only on workout activities.

Discussion

Use this convenience method to create a predicate that matches against an activity’s duration. To use this predicate, call predicateForWorkouts(activityPredicate:) to wrap this predicate inside a workout predicate. You can then use the workout predicate in your query.

The following sample creates a predicate for matching workout activities with a duration of 30 minutes or longer.

let longWorkoutActivityPredicate = HKQuery.predicateForWorkoutActivities(operatorType: .greaterThanOrEqualTo, duration: 60.0 * 30.0)


// Wrap the activity predicate inside a workout predicate.
let workoutPredicate = HKQuery.predicateForWorkouts(activityPredicate: longWorkoutActivityPredicate)

See Also

Related Documentation

Creating workout activity predicates