Skip to content

Instantly share code, notes, and snippets.

@hungtruong
Created May 1, 2019 03:44
Show Gist options
  • Save hungtruong/918839f7ba4a213c92817b387a6fd91f to your computer and use it in GitHub Desktop.
Save hungtruong/918839f7ba4a213c92817b387a6fd91f to your computer and use it in GitHub Desktop.
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) {
for type in collectedTypes {
guard let quantityType = type as? HKQuantityType else {
return
}
switch quantityType {
case HKQuantityType.quantityType(forIdentifier: .heartRate):
guard let statistics = workoutBuilder.statistics(for: quantityType),
let value = statistics.mostRecentQuantity()?.doubleValue(for: heartRateUnit)
else {
break
}
self.updateHeartRate(Int(value))
default:
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment