Created
March 1, 2018 21:02
-
-
Save eriadam/5f5388c1ceb5f23681f8dd44a125bf06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// When the completion is called, an other query is executed | |
/// to fetch the latest heart rate | |
self.fetchLatestHeartRateSample(completion: { sample in | |
guard let sample = sample else { | |
return | |
} | |
/// The completion in called on a background thread, but we | |
/// need to update the UI on the main. | |
DispatchQueue.main.async { | |
/// Converting the heart rate to bpm | |
let heartRateUnit = HKUnit(from: "count/min") | |
let heartRate = sample | |
.quantity | |
.doubleValue(for: heartRateUnit) | |
/// Updating the UI with the retrieved value | |
self?.heartRateLabel.setText("\(Int(heartRate))") | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment