I'm working on an app that allows me to see a person's water consumption, but I am not able to access HealthKit
data. How do I read and write .liter()
data?
Thanks
HKUnit.liter()
returns an object that is used for interpreting measurements, and is not a HealthKit data type itself. If you want write water consumption you'll need to create instances of HKQuantitySample
with the type HKQuantityTypeIdentifierDietaryWater
. To read this data from HealthKit, I recommend using HKStatisticsQuery
or HKStatisticsCollectionQuery
to query aggregate values for particular time ranges. For examples of how to use these APIs, there is documentation here and here.