Trying to use Swift HealthKit causes Apple WatchKit to crash when view loads?

I am trying to use the HealthKit API in my Apple Watch app but could not get it to work. I tried copying Apple's demo program SpeedySloth found here: https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/speedysloth_creating_a_workout

Downloading this app and running it works but if I copy each line of code line for line it doesn't work. Is there anything else that needs to be set for it to work. I know NSHealthShareUsageDescription and NSHealthUpdateUsageDescription in Info.plist need to be set which I have done but it still crashes when the view loads.

There are no errors displayed in the console.

Any ideas of anything I've missed?