Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public func subscribeToHeartBeatChanges() {
// Creating the sample for the heart rate
guard let sampleType: HKSampleType =
HKObjectType.quantityType(forIdentifier: .heartRate) else {
/// Creating an observer, so updates are received whenever HealthKit’s
// heart rate data changes.
self.heartRateQuery = HKObserverQuery.init(
sampleType: sampleType,
predicate: nil) { [weak self] _, _, error in
guard error == nil else {
/// Yay, heart beat update!
if let query = self.heartRateQuery {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment