Search code examples
swiftwatchkithealthkitwatchos-4

HealthKit - accumulate energy burned in watchOS 4


In watchOS 3, when you wanted to accumulate energy burned, you could use something like:

totalEnergyBurned.addQuantities(from: samples, unit: HKUnit.calorie())

Now in WatchOS 4, HKUnit.calorie() is deprecated and has been replaced by HKUnit.smallCalorie() and HKUnit.largeCalorie().

So, to measure the energy burned now, do we accumulate smallCalorie(), largeCalorie() or both?

Unfortunately the Apple documentation today is still in BETA and doesn't tell us much yet.


Solution

  • According to Apple's documentation, HKUnit.calorie() represents gram calorie. You should use smallCalorie (a.k.a. gram calorie) for the same purpose.

    largeCalorie = smallCalorie * 1000