below is my code of reading data from HealthKit for Multiple Data
but for reading Multiple data using Set() it shows
"Cannot convert value of type 'Set' to expected argument type 'HKQuantityType' "
func readData(completion: @escaping (HKStatisticsCollection?)-> Void){
let stepCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!
let MoveCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.appleMoveTime)!
let DistanceCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!
let Activitysummary = Set([stepCount,MoveCount,DistanceCount])
let startDate = Calendar.current.date(byAdding: .day, value: -7, to: Date())
//MARK: here we setting our start time at 12.00 AM
let anchorDate = Date.monday12AM()
//MARK: we going to calculate the value for each day
let daily = DateComponents(day : 1)
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: Date(), options: .strictStartDate)
//MARK: .cummulativesum -> iPhone and Apple Watch Difference
query = HKStatisticsCollectionQuery(quantityType: Activitysummary, quantitySamplePredicate: predicate,options: .cumulativeSum, anchorDate: anchorDate, intervalComponents: daily)
//MARK: here in ActivitySummary it show the error
query!.initialResultsHandler = { query,statisticsCollection, error in
completion(statisticsCollection)
}
if let healthStore = healthStore, let query = self.query{
healthStore.execute(query)
}
}
I'm not sure it is possible to have query with several identifiers.
So you could try to have a query for each stepCount, moveCount, distanceCount and compute statistics yourself for the 3.
can only query only one HKQuantityIdentifier at a time