Contents

addWorkoutActivity(_:completion:)

Adds a workout activity to the workout builder.

Declaration

func addWorkoutActivity(_ workoutActivity: HKWorkoutActivity, completion: @escaping  @Sendable (Bool, (any Error)?) -> Void)
func addWorkoutActivity(_ workoutActivity: HKWorkoutActivity) async throws

Parameters

  • workoutActivity:

    The workout activity to add.

  • completion:

    A callback handler that the system calls after adding the workout activity. The system calls the callback handler on an anonymous background queue.

    The callback handler takes the following parameters:

    success

    Contains True if the builder successfully added the activity.

    error

    If the success parameter is False, this parameter contains information about the error; otherwise, it’s nil.

Discussion

You can call this method repeatedly to incrementally add activities to the builder. Calling this method after calling finishWorkout(completion:) fails with an error.

If you add an HKWorkoutActivity object that doesn’t have an endDate, you can set the end date by calling updateActivity(uuid:end:completion:).

See Also

Managing workout activities