Contents

HKUnit

A class for managing the units of measure within HealthKit.

Declaration

class HKUnit

Mentioned in

Overview

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 HKQuantity.

Using Units

Like many HealthKit classes, the HKUnit class is not extendable and should not be subclassed.

The 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 HKTimeUnit subclass.

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.

Topics

Working with units

Working with formatter units

Constructing mass units

Constructing length units

Constructing volume units

Constructing pressure units

Constructing time units

Constructing energy units

Constructing power units

Constructing temperature units

Constructing hearing sensitivity units

Constructing frequency units

Constructing vision units

Constructing angle units

Constructing electrical conductance units

Electrical potential difference

Constructing pharmacology units

Constructing scalar units

Performing unit math

Constants

Initializers

Type Methods

See Also

Units and quantities