Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/// 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 {
/// 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
.doubleValue(for: heartRateUnit)
/// Updating the UI with the retrieved value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment