---
title: "finishWorkout(completion:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkworkoutbuilder/finishworkout(completion:)"
---

# finishWorkout(completion:)

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

## Declaration

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

```swift
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:

## Mentioned in

Running workout sessions Dividing a HealthKit workout into activities

## Discussion

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

- [endCollection(withEnd:completion:)](healthkit/hkworkoutbuilder/endcollection(withend:completion:).md)
- [endDate](healthkit/hkworkoutbuilder/enddate.md)
- [discardWorkout()](healthkit/hkworkoutbuilder/discardworkout().md)
