Search code examples
iosapple-watchhealthkit

Retrieve HKWorkoutTypeIdentifier from a HealthKit query


In a HealthKit query, is there a way to retrieve the original HKWorkoutTypeIdentifier used to store the data?

I know you can use HKWorkoutTypeIdentifier to query for specific workout types; but, that's not what I'm trying to do. The question I want to answer, is "What types of workouts has the user done?"

The Apple Health app has a list, as do some third-party apps. But I can't figure out how they're doing this.

Any ideas?


Solution

  • Once you've got the samples returned from the query, you can use .workoutActivityType on each workout sample to access the HKWorkoutActivityType that's set for that sample.