Contents

finishWorkout(completion:)

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

Declaration

func finishWorkout(completion: @escaping  @Sendable (HKWorkout?, (any Error)?) -> Void)
func finishWorkout() async throws -> HKWorkout?

Parameters

  • completion:

    A completion handler that the system calls after the HKWorkout object has been created and saved. This handler takes the following parameters:

    workout

    An object that represents the finished workout. If an error occurred, the system sets this parameter to nil. If both this and the error parameter are nil then finishing the workout succeeded but the workout sample is not available because the device is locked.

    error

    If an error occurred, this parameter contains information about the error. Otherwise, it’s nil.

Mentioned in

Discussion

You must call endCollection(withEnd:completion:) before calling this method. This function returns nil if finishing the workout succeeded but the workout sample is not available because the device is locked.

See Also

Ending the workout