Type Method

predicateForWorkouts(with:totalFlightsClimbed:)

Returns a predicate that matches workout samples based on the number of flights climbed.

Declaration

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

Parameters

operatorType

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

totalFlightsClimbed

A quantity representing the target number of flights climbed.

Return Value

A predicate that matches workouts based on the number of flights climbed.

Discussion

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

let flightsClimbed = HKQuantity(unit: HKUnit.count(), doubleValue: 10.0)
let tenFlightsClimbed = HKQuery.predicateForWorkouts(with: .greaterThanOrEqualTo, totalFlightsClimbed: flightsClimbed)

// Creating a predicate using a predicate format string.
let explicitTenFlightsClimbed = NSPredicate(format: "%K >= %@",
                                            HKPredicateKeyPathWorkoutTotalFlightsClimbed,
                                            flightsClimbed)

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

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

class func predicateForWorkouts(with: HKWorkoutActivityType) -> NSPredicate

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

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software