<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKWorkoutBuilder/finishWorkout(completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKWorkoutBuilder(im)finishWorkoutWithCompletion:"
  },
  "title" : "finishWorkout(completion:)"
}
-->

# finishWorkout(completion:)

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

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

## 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`.

## Discussion

You must call [`endCollection(withEnd:completion:)`](/documentation/HealthKit/HKWorkoutBuilder/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)