HealthKit uses quantity objects to store numerical data. Quantities store a value for a given unit. You can request the value in any compatible units. For example, if you can create a length property in feet, you can then request the value in meters. The quantity object automatically converts its value to the requested units, as needed.


Quantities are immutable objects: Their values are set when the object is first created and cannot change.

Subclassing Notes

Like many HealthKit classes, the HKQuantity class is not extendible and should not be subclassed. To help promote sharing data between apps, HKQuantity objects use only the units defined by the HKUnit class.


Creating Quantities

init(unit: HKUnit, doubleValue: Double)

Instantiates and returns a new quantity object.

Working With Units

func `is`(compatibleWith: HKUnit)

Returns a boolean value indicating whether the quantity is compatible with the provided unit.

func doubleValue(for: HKUnit)

Returns the quantity’s value in the provided unit.

Comparing Quantities

func compare(HKQuantity)

Compares two values after converting them to the same units.


Inherits From