finishRoute(with:metadata:completion:)
Creates, saves, and associates the route with the provided workout.
Declaration
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 -> HKWorkoutRouteParameters
- 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 Nsstring objects. The values may be Hkquantity, Nsstring, Nsnumber, or Nsdate objects. For a complete list of predefined metadata keys, see 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:
workoutRouteThe workout route, or
nilif an error occurred. If successful, the system has already associated the route with the provided workout and saved it to the HealthKit store.errorAn object that describes the error, if an error has occurred; otherwise,
nil.
Mentioned in
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.
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 object).