From the course: Using the HealthKit API to Build iOS and watchOS Applications

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Save workout to HealthKit

Save workout to HealthKit

- [Narrator] We've just implemented the Workout Session Delegate so we can see what's happening to our workout session. And now we can actually save our workout. We're going to scroll back up into the main part of our interface controller. And open up a new line on 96. We're going to define our save workout function, Func saveWorkout. Inside there, we're going to create a new variable constant, let workout = HKWorkout. We're going to pick the basic one with an activity type start and end date. Our activity type we picked earlier was other, we're going to stick with that. Start and end date, we actually want to track when we're starting our workout session. So we're going to define a variable at the top of our class. Open up a new line on 25, variable workout start date. We're going to define it as a type of date, and it's an optional. And we're going to go to our start workout session method and open up a new line on line 89, and set our self.WorkoutStartDate to be a new date. That'll…

Contents