Last active
March 18, 2019 05:36
-
-
Save NSAmit/3a5b2e205348cdbf420bda9cfe005152 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
func getRecordForType(type: HKClinicalTypeIdentifier, recordReadCompletionHandler:@escaping ([HKClinicalRecord]?) -> Void) { | |
guard let healthRecordType = HKObjectType.clinicalType(forIdentifier: type) else { | |
fatalError("*** Unable to create the record type ***") | |
} | |
let healthRecordQuery = HKSampleQuery(sampleType: healthRecordType, predicate: nil, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in | |
guard let actualSamples = samples else { | |
// Handle the error here. | |
print("*** An error occurred: \(error?.localizedDescription ?? "nil") ***") | |
recordReadCompletionHandler(nil) | |
return | |
} | |
let healthRecordSamples = actualSamples as? [HKClinicalRecord] | |
recordReadCompletionHandler(healthRecordSamples) | |
} | |
// Execute the query using single HKHealthStore execute API | |
healthStore.execute(healthRecordQuery) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment