11. FEATURES
> Super simple to access HealthKit
> Cuztomizable preferences
> Well-designed for workout app
> Easy way to save workout data in HealthKit
14. CONTEXT PROTOCOL
public protocol Context {
var activityType: HKWorkoutActivityType { get }
var locationType: HKWorkoutSessionLocationType { get }
var distanceUnit: HKUnit { get }
var activeEnergyUnit: HKUnit { get }
var heartRateUnit: HKUnit { get }
var distanceType: HKQuantityType { get }
var activeEnergyType: HKQuantityType { get }
var heartRateType: HKQuantityType { get }
var shareIdentifiers: [String] { get }
var readIdentifiers: [String] { get }
}
15. CONTEXT EXTENSION
public extension Context {
public var activityType: HKWorkoutActivityType {
return .Running
}
public var locationType: HKWorkoutSessionLocationType {
return .Outdoor
}
public var distanceUnit: HKUnit {
return HKUnit.meterUnitWithMetricPrefix(.Kilo)
}
public var activeEnergyUnit: HKUnit {
return HKUnit.kilocalorieUnit()
}
public var heartRateUnit: HKUnit {
return HKUnit(fromString: "count/min")
}
...
}
16. STRUCT CONFORMED CONTEXT
struct CardioContext: Context {
var locationType: HKWorkoutSessionLocationType {
return .Indoor
}
var distanceUnit: HKUnit {
return HKUnit.mileUnit()
}
var shareIdentifiers: [String] {
return []
}
}
19. UPDATE HANDLERS
cardio.distanceHandler = { distance, total in
}
cardio.activeEnergyHandler = { activeEnergy, total in
}
cardio.heartRateHandler = { heartRate, average in
}