Ok, so the property workoutActivityType
of the HKWorkout
returns a NSInteger
.
Here is a list with the activities: workoutActivityType list
For now, I will create a plist
and look for the activity name when I get the integer
. But it seems a little odd to have to go through this.
Do I need to find out which activity it is on my own or is there something I am missing?
For anyone still coming across this now, I have put together a simple HKWorkoutActivityType
extension in swift to allow mapping to these types to user friendly strings, and also to appropriate emoji representations where available: https://github.com/georgegreenoflondon/HKWorkoutActivityType-Descriptions/.
The relevant snippet for this question being:
extension HKWorkoutActivityType {
/*
Simple mapping of available workout types to a human readable name.
*/
var name: String {
switch self {
case .americanFootball: return "American Football"
case .archery: return "Archery"
case .australianFootball: return "Australian Football"
case .badminton: return "Badminton"
case .baseball: return "Baseball"
case .basketball: return "Basketball"
case .bowling: return "Bowling"
case .boxing: return "Boxing"
case .climbing: return "Climbing"
case .crossTraining: return "Cross Training"
case .curling: return "Curling"
case .cycling: return "Cycling"
case .dance: return "Dance"
case .danceInspiredTraining: return "Dance Inspired Training"
case .elliptical: return "Elliptical"
case .equestrianSports: return "Equestrian Sports"
case .fencing: return "Fencing"
case .fishing: return "Fishing"
case .functionalStrengthTraining: return "Functional Strength Training"
case .golf: return "Golf"
case .gymnastics: return "Gymnastics"
case .handball: return "Handball"
case .hiking: return "Hiking"
case .hockey: return "Hockey"
case .hunting: return "Hunting"
case .lacrosse: return "Lacrosse"
case .martialArts: return "Martial Arts"
case .mindAndBody: return "Mind and Body"
case .mixedMetabolicCardioTraining: return "Mixed Metabolic Cardio Training"
case .paddleSports: return "Paddle Sports"
case .play: return "Play"
case .preparationAndRecovery: return "Preparation and Recovery"
case .racquetball: return "Racquetball"
case .rowing: return "Rowing"
case .rugby: return "Rugby"
case .running: return "Running"
case .sailing: return "Sailing"
case .skatingSports: return "Skating Sports"
case .snowSports: return "Snow Sports"
case .soccer: return "Soccer"
case .softball: return "Softball"
case .squash: return "Squash"
case .stairClimbing: return "Stair Climbing"
case .surfingSports: return "Surfing Sports"
case .swimming: return "Swimming"
case .tableTennis: return "Table Tennis"
case .tennis: return "Tennis"
case .trackAndField: return "Track and Field"
case .traditionalStrengthTraining: return "Traditional Strength Training"
case .volleyball: return "Volleyball"
case .walking: return "Walking"
case .waterFitness: return "Water Fitness"
case .waterPolo: return "Water Polo"
case .waterSports: return "Water Sports"
case .wrestling: return "Wrestling"
case .yoga: return "Yoga"
// iOS 10
case .barre: return "Barre"
case .coreTraining: return "Core Training"
case .crossCountrySkiing: return "Cross Country Skiing"
case .downhillSkiing: return "Downhill Skiing"
case .flexibility: return "Flexibility"
case .highIntensityIntervalTraining: return "High Intensity Interval Training"
case .jumpRope: return "Jump Rope"
case .kickboxing: return "Kickboxing"
case .pilates: return "Pilates"
case .snowboarding: return "Snowboarding"
case .stairs: return "Stairs"
case .stepTraining: return "Step Training"
case .wheelchairWalkPace: return "Wheelchair Walk Pace"
case .wheelchairRunPace: return "Wheelchair Run Pace"
// iOS 11
case .taiChi: return "Tai Chi"
case .mixedCardio: return "Mixed Cardio"
case .handCycling: return "Hand Cycling"
// iOS 13
case .discSports: return "Disc Sports"
case .fitnessGaming: return "Fitness Gaming"
// Catch-all
default: return "Other"
}
}
}
Unfortunately, apple only provides an enum and you would have to implement your own names. A good idea is to lazily instantiate a dictionary including keys of NSNumber
(Object wrapped NSInteger
) and values of strings. Should be quite easy to make and unfortunately the only solution.
extension HKWorkoutActivityType {
var name: String {
switch self {
case .americanFootball: return "American Football"
case .archery: return "Archery"
case .australianFootball: return "Australian Football"
case .badminton: return "Badminton"
case .baseball: return "Baseball"
case .basketball: return "Basketball"
case .bowling: return "Bowling"
case .boxing: return "Boxing"
case .climbing: return "Climbing"
case .cricket: return "Cricket"
case .crossTraining: return "Cross Training"
case .curling: return "Curling"
case .cycling: return "Cycling"
case .dance: return "Dance"
case .danceInspiredTraining: return "Dance Inspired Training"
case .elliptical: return "Elliptical"
case .equestrianSports: return "Equestrian Sports"
case .fencing: return "Fencing"
case .fishing: return "Fishing"
case .functionalStrengthTraining: return "Functional Strength Training"
case .golf: return "Golf"
case .gymnastics: return "Gymnastics"
case .handball: return "Handball"
case .hiking: return "Hiking"
case .hockey: return "Hockey"
case .hunting: return "Hunting"
case .lacrosse: return "Lacrosse"
case .martialArts: return "Martial Arts"
case .mindAndBody: return "Mind and Body"
case .mixedMetabolicCardioTraining: return "Mixed Metabolic Cardio Training"
case .paddleSports: return "Paddle Sports"
case .play: return "Play"
case .preparationAndRecovery: return "Preparation and Recovery"
case .racquetball: return "Racquetball"
case .rowing: return "Rowing"
case .rugby: return "Rugby"
case .running: return "Running"
case .sailing: return "Sailing"
case .skatingSports: return "Skating Sports"
case .snowSports: return "Snow Sports"
case .soccer: return "Soccer"
case .softball: return "Softball"
case .squash: return "Squash"
case .stairClimbing: return "Stair Climbing"
case .surfingSports: return "Surfing Sports"
case .swimming: return "Swimming"
case .tableTennis: return "Table Tennis"
case .tennis: return "Tennis"
case .trackAndField: return "Track and Field"
case .traditionalStrengthTraining: return "Traditional Strength Training"
case .volleyball: return "Volleyball"
case .walking: return "Walking"
case .waterFitness: return "Water Fitness"
case .waterPolo: return "Water Polo"
case .waterSports: return "Water Sports"
case .wrestling: return "Wrestling"
case .yoga: return "Yoga"
// - iOS 10
case .barre: return "Barre"
case .coreTraining: return "Core Training"
case .crossCountrySkiing: return "Cross Country Skiing"
case .downhillSkiing: return "Downhill Skiing"
case .flexibility: return "Flexibility"
case .highIntensityIntervalTraining: return "High Intensity Interval Training"
case .jumpRope: return "Jump Rope"
case .kickboxing: return "Kickboxing"
case .pilates: return "Pilates"
case .snowboarding: return "Snowboarding"
case .stairs: return "Stairs"
case .stepTraining: return "Step Training"
case .wheelchairWalkPace: return "Wheelchair Walk Pace"
case .wheelchairRunPace: return "Wheelchair Run Pace"
// - iOS 11
case .taiChi: return "Tai Chi"
case .mixedCardio: return "Mixed Cardio"
case .handCycling: return "Hand Cycling"
// - iOS 13
case .discSports: return "Disc Sports"
case .fitnessGaming: return "Fitness Gaming"
// - iOS 14
case .cardioDance: return "Cardio Dance"
case .socialDance: return "Social Dance"
case .pickleball: return "Pickleball"
case .cooldown: return "Cooldown"
// - Other
case .other: return "Other"
@unknown default: return "Other"
}
}
}
The actual version of George Green's answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With