<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKWorkoutRouteBuilder/finishRoute(with:metadata:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKWorkoutRouteBuilder(im)finishRouteWithWorkout:metadata:completion:"
  },
  "title" : "finishRoute(with:metadata:completion:)"
}
-->

# finishRoute(with:metadata:completion:)

Creates, saves, and associates the route with the provided workout.

```
func finishRoute(with workout: HKWorkout, metadata: [String : Any]?, completion: @escaping @Sendable (HKWorkoutRoute?, (any Error)?) -> Void)
```

```
func finishRoute(with workout: HKWorkout, metadata: [String : Any]?) async throws -> HKWorkoutRoute
```

## Parameters

`workout`

The workout to associate with the route. You must have already saved this workout to the HealthKit store.

`metadata`

The metadata dictionary can contain extra information describing this sample. The dictionary’s keys are all <doc://com.apple.documentation/documentation/Foundation/NSString> objects. The values may be [`HKQuantity`](/documentation/HealthKit/HKQuantity), <doc://com.apple.documentation/documentation/Foundation/NSString>, <doc://com.apple.documentation/documentation/Foundation/NSNumber>, or <doc://com.apple.documentation/documentation/Foundation/NSDate> objects. For a complete list of predefined metadata keys, see <doc://com.apple.healthkit/documentation/HealthKit/metadata-keys>.

    Using predefined keys helps facilitate sharing data between apps; however, you are also encouraged to create your own custom keys as needed to extend the HealthKit quantity sample’s capabilities.

`completion`

A block called after the system has saved the route data. The system passes the block the following parameters:

- `workoutRoute`: The workout route, or `nil` if an error occurred. If successful, the system has already associated the route with the provided workout and saved it to the HealthKit store.
- `error`: An object that describes the error, if an error has occurred; otherwise, `nil`.

## Discussion

Call this method after adding all the route data to the builder. The builder creates the route and saves it to the HealthKit store. It also associates the route with the provided workout. You cannot associate the route with another workout.

> Note:
> You must call ``doc://com.apple.healthkit/documentation/HealthKit/HKWorkoutRouteBuilder/finishRoute(with:metadata:completion:)`` before the system deallocates the builder. Failure to do so results in a loss of all route data added to the builder.

This method fails if you haven’t added any location data to the builder. The completion handler returns an error and `nil` for the route.

Additionally, this method invalidates the builder. Any further calls to the builder returns an error. To subsequently access the workout route, use a query (for example, an [`HKSampleQuery`](/documentation/HealthKit/HKSampleQuery) object).

---

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)