Introduction to sleep analysis with HealthKit with Swift
['Benoit Pasquier']
Benoit Pasquier - Swift, Data and more
strictStartDate ) // I had a sortDescriptor to get the recent data first let sortDescriptor = NSSortDescriptor ( key : HKSampleSortIdentifierEndDate , ascending : false ) // we create our query with a block completion to execute let query = HKSampleQuery ( sampleType : sleepType , predicate : predicate , limit : 30 , sortDescriptors : [ sortDescriptor ]) { ( query , result , error ) in if error != nil { // handle error return } if let result = result { // do something with those data result . But careful with what you read: if an other app saved inaccurate data in Health app, you can compromise your own when you read them.