I have requested the access from the HealthKit by below code
let calorieCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.activeEnergyBurned)!
and it working perfectly but not able to read the data using Query after reading the documentation I have found out HKStatisticsQuery is used for Query
func CaloriesBurned() {
let activeEnergy = HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)!
let startDate = Calendar.current.date(byAdding: .day,value: -7, to: Date())
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: Date(), options: .strictStartDate)
let query = HKStatisticsQuery(quantityType: activeEnergy, quantitySamplePredicate: predicate,completionHandler: <#T##(HKStatisticsQuery, HKStatistics?, Error?) -> Void#>))
}
but I don't understand what should be written in completion handler in above code to read the active Energy Burned
I have read already documentation if anyone has sample code to read energy burned or sample code on how to use HKStatisticsQuery