Distance doesnt get associated with HKWorkout

I am working on a running app for the iPhone.

The Workout gets created using the HKWorkoutBuilder – according to the Documentation. The activity type is set to .running in the Configuration.

After calling endCollection() – before calling finishWorkout()– on the HKWorkoutBuilder I am adding distance samples to the Workout.

Weirdly, the totalDistance of the Workout doesnt get populated. And if I take a look into the Health App there is no total distance either – but a »Distance Walking Running« with a double unit (like 10.5 km km), and the distance samples ive added. In the overview of the trainings (with the big app icon left hand side) there is even a blank spot where the distance is supposed to be, I think. (like Running: 35 Min. | --).

Do I miss something here, or is this
Answered by GustavGustavson in 669674022
Just noticed that I was not adding the distance samples with a completion handler – and did not waited for completition until I called finishWorkout() on the builder. I think that messed up the workout somehow.
Accepted Answer
Just noticed that I was not adding the distance samples with a completion handler – and did not waited for completition until I called finishWorkout() on the builder. I think that messed up the workout somehow.
Distance doesnt get associated with HKWorkout
 
 
Q