Class

HKWorkoutBuilder

A builder object that incrementally constructs a workout.

Declaration

@interface HKWorkoutBuilder : NSObject

Overview

Incrementally collect samples and events associated with a workout. When the workout ends, call finishWorkoutWithCompletion: to create an HKWorkout sample and save it to the HealthKit store.

For watchOS, use an HKWorkoutSession and an HKLiveWorkoutBuilder instead.

Topics

Creating the Builder

- initWithHealthStore:configuration:device:

Returns a new workout builder object that is not connected to a workout session or other data source.

device

The device associated with the workout.

workoutConfiguration

The configuration information for the workout.

Starting the Workout

- beginCollectionWithStartDate:completion:

Sets the workout’s start date and begins building the workout.

startDate

The workout’s start date and time.

- elapsedTimeAtDate:

Calculates the duration of the workout at the specified time.

Associating Samples with the Workout

- addSamples:completion:

Adds a sample to be associated with the workout.

- seriesBuilderForType:

Returns the series builder for the specified type, creating a new builder, if necessary.

- statisticsForType:

Returns the statistics calculated for matching samples added to the workout.

Adding Metadata to the Workout

- addMetadata:completion:

Adds metadata to be saved with the workout.

metadata

The metadata the builder saves with the workout.

Adding Events to the Workout

- addWorkoutEvents:completion:

Adds a workout event to the builder.

workoutEvents

The list of events added to the workout.

Ending the Workout

- endCollectionWithEndDate:completion:

Stops the collection of data, sets the workout’s end date, and deactivates the workout builder.

endDate

The workout’s end date and time.

- finishWorkoutWithCompletion:

Creates the workout, using the samples and events added to the builder, and saves it to the HealthKit store.

- discardWorkout

Stops the collection of data and discards the current results without saving the workout.

Relationships

Inherits From

See Also

Samples

Using Workout Samples

Record a physical activity using workout samples.

HKWorkout

A workout sample stores information about a single physical activity.

HKWorkoutType

A type that identifies samples that store information about a workout.

HKWorkoutTypeIdentifier

The workout type identifier.

HKWorkoutActivityType

The type of activity performed during a workout.

HKWorkoutEvent

An object representing an important event during a workout.