我正在开发一项功能,可以从Health应用程序中读取HKWorkout样本。我想向用户显示描述字符串,告诉他们锻炼的内容。我可以看到的唯一属性可能向用户指示样本代表什么类型的活动类型是workoutActivityType
属性。我该如何将HKWorkoutActivityType转换为用户友好的字符串?我错过了什么,或者是否有更好的方式来获得HKWorkout样本的描述?
答案 0 :(得分:2)
public 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"
}
}
}
来源:https://github.com/georgegreenoflondon/HKWorkoutActivityType-Descriptions/。
答案 1 :(得分:1)
HealthKit没有用于本地化HKWorkoutActivityType值的API。您需要实现自己的映射。