Contents

predicateForWorkoutActivities(start:end:options:)

Returns a predicate for workout activities that occur between the start and end date.

Declaration

class func predicateForWorkoutActivities(start startDate: Date?, end endDate: Date?, options: HKQueryOptions = []) -> NSPredicate

Parameters

  • startDate:

    The start date for the target time interval.

  • endDate:

    The end date for the target time interval.

  • options:

    A constant that specifies how HealthKit compares the sample’s start and end date with the target time interval. For a list of possible values, see Hkqueryoptions.

Discussion

Use this convenience method to create a predicate that matches workout activities that occur between the specified start and end dates. 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 workout activities within the last 30 minutes.

let end = Date()
let start = end.advanced(by: -30.0 * 60.0)

let recentActivityPredicate =
HKQuery.predicateForWorkoutActivities(start: start, end: end)

let workoutPredicate =
HKQuery.predicateForWorkouts(activityPredicate: recentActivityPredicate)

See Also

Creating workout activity predicates