I am using HealthKit
to make a sample query data such as the step count. However, when I test it on my device I get a bunch of different results. Now since I have the results from different sources and different days such as [16 count, 50 count, .....]
. Now I want to add up all of the data into one value. How would I achieve this? For example if I make a sample query to HealthKit
, and it returns [15 count, 20 count]
I want to 15 + 20 to get 35 count. How would I do that?
Here is the code that I used to query the data:
func getStepsHealthData() {
let stepsHealthDataQuery = HKSampleQuery(sampleType: stepsHealth, predicate: predicate, limit: Int(HKObjectQueryNoLimit), sortDescriptors: nil) {
(query, results, error) in
let stepsUnit = HKUnit.countUnit()
for result in (results as? [HKQuantitySample])! {
stepCount = result.quantity.doubleValueForUnit(stepsUnit)
}
}
healthKitStore?.executeQuery(stepsHealthDataQuery)
}