HKUnit class to manage units of measure within HealthKit.
- iOS 8.0+
- watchOS 2.0+
The unit class supports most standard SI units (meters, seconds, and grams), SI units with prefixes (centimeters, milliseconds and kilograms) and equivalent non-SI units (feet, minutes, and pounds). HealthKit also supports creating complex units by mathematically combining existing units.
You use units when working with HealthKit quantities. Quantities store both the value (as a
double data type) and its corresponding unit. You can then request the value from the quantity in any compatible units. For more information on working with quantities, see
Like many HealthKit classes, the
HKUnit class is not extendable and should not be subclassed.
HKUnit class is implemented using a facade design pattern. It uses custom subclasses to represent instances of the different unit types. For example, the
second() convenience method actually returns an instance of the private
Additionally, the unit class uses a single unit instance to represent all copies of the same unit in your app, wherever possible. For example, two calls to the
second() method return the same unit object. This helps reduce the amount of memory used by unit instances.