Type Method

predicateForObjects(from:)

Returns a predicate that matches any objects that have been associated with the provided workout.

Declaration

class func predicateForObjects(from workout: HKWorkout) -> NSPredicate

Parameters

workout

The workout you are searching for.

Return Value

A predicate that matches any objects that have been added to the provided workout.

Discussion

Use this convenience method to create a predicate that matches all the HealthKit objects for a given workout. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

let workoutObjects = HKQuery.predicateForObjectsFromWorkout(workout)
 
let explicitWorkoutObjects =
    NSPredicate(format: "%K == %@", HKPredicateKeyPathWorkout, workout)

See Also

Creating Workout Predicates

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.

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