Class

HKUnit

A class for managing the units of measure within HealthKit.

Declaration

@interface HKUnit : NSObject

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 secondUnit 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 secondUnit method return the same unit object. This helps reduce the amount of memory used by unit instances.

Topics

Working with Units

+ unitFromString:

Returns the unit instance described by the provided string.

unitString

A string representation of the unit object.

- isNull

Returns a Boolean value indicating whether the unit is null.

Working with Formatter Units

+ energyFormatterUnitFromUnit:

Converts a HealthKit unit object into a corresponding energy formatter enumeration value.

+ unitFromEnergyFormatterUnit:

Converts an energy formatter enumeration value into a corresponding HealthKit unit object.

+ lengthFormatterUnitFromUnit:

Converts a HealthKit unit object into a corresponding length formatter enumeration value.

+ unitFromLengthFormatterUnit:

Converts a length formatter enumeration value into a corresponding HealthKit object.

+ massFormatterUnitFromUnit:

Converts a HealthKit unit object into a corresponding mass formatter enumeration value.

+ unitFromMassFormatterUnit:

Converts a mass formatter enumeration value into a corresponding HealthKit unit object.

Constructing Mass Units

+ gramUnit

Returns a HealthKit unit for measuring mass in grams.

+ gramUnitWithMetricPrefix:

Returns a HealthKit unit for measuring mass, using gram units with the provided prefix.

+ ounceUnit

Returns a HealthKit unit for measuring mass in ounces.

+ poundUnit

Returns a HealthKit unit for measuring mass in pounds.

+ stoneUnit

Returns a HealthKit unit for measuring mass in stones.

+ moleUnitWithMolarMass:

Returns a HealthKit unit for measuring mass in moles for a given molar mass.

+ moleUnitWithMetricPrefix:molarMass:

Returns a HealthKit unit for measuring mass in moles, with the given prefix and molar mass.

HKUnitMolarMassBloodGlucose

The molecular mass of blood glucose, typically used to create mole units for blood glucose.

Constructing Length Units

+ meterUnit

Returns a HealthKit unit for measuring length in meters.

+ meterUnitWithMetricPrefix:

Returns a HealthKit unit for measuring length, using meter units with the provided prefix.

+ inchUnit

Returns a HealthKit unit for measuring length in inches.

+ footUnit

Returns a HealthKit unit for measuring length in feet.

+ yardUnit

Returns a HealthKit unit for measuring length in yards.

+ mileUnit

Returns a HealthKit unit for measuring length in miles.

Constructing Volume Units

+ literUnit

Returns a HealthKit unit for measuring volume in liters.

+ literUnitWithMetricPrefix:

Returns a HealthKit unit for measuring volume, using liter units with the provided prefix.

+ fluidOunceUSUnit

Returns a HealthKit unit for measuring volume in US fluid ounces.

+ fluidOunceImperialUnit

Returns a HealthKit unit for measuring volume in imperial fluid ounces.

+ cupUSUnit

Returns a HealthKit unit for measuring volume in US cups.

+ cupImperialUnit

Returns a HealthKit unit for measuring volume in imperial cups.

+ pintUSUnit

Returns a HealthKit unit for measuring volume in US pints.

+ pintImperialUnit

Returns a HealthKit unit for measuring volume in imperial pints.

Constructing Pressure Units

+ pascalUnit

Returns a HealthKit unit for measuring pressure in pascals.

+ pascalUnitWithMetricPrefix:

Returns a HealthKit unit for measuring pressure, using pascal units with the provided prefix.

+ millimeterOfMercuryUnit

Returns a HealthKit unit for measuring pressure in millimeters of mercury.

+ centimeterOfWaterUnit

Returns a HealthKit unit for measuring pressure in centimeters of water.

+ atmosphereUnit

Returns a HealthKit unit for measuring pressure in atmospheres.

+ decibelAWeightedSoundPressureLevelUnit

Returns a HealthKit unit for measuring the difference between the local pressure and the ambient atmospheric pressure caused by sound.

Constructing Time Units

+ secondUnit

Returns a HealthKit unit for measuring time in seconds.

+ secondUnitWithMetricPrefix:

Returns a HealthKit unit for measuring time, using second units with the provided prefix.

+ minuteUnit

Returns a HealthKit unit for measuring time in minutes.

+ hourUnit

Returns a HealthKit unit for measuring time in hours.

+ dayUnit

Returns a HealthKit unit for measuring time in days.

Constructing Energy Units

+ jouleUnit

Returns a HealthKit unit for measuring energy in joules.

+ jouleUnitWithMetricPrefix:

Returns a HealthKit unit for measuring energy, using joule units with the provided prefix.

+ calorieUnit

Returns a HealthKit unit for measuring energy in calories.

Deprecated
+ kilocalorieUnit

Returns a HealthKit unit for measuring energy in kilocalories.

+ largeCalorieUnit

Returns a HealthKit unit for measuring energy in large calories (Cal).

+ smallCalorieUnit

Returns a HealthKit unit for measuring energy in small calories (cal).

Constructing Temperature Units

+ degreeCelsiusUnit

Returns a HealthKit unit for measuring temperature in degrees Celsius.

+ degreeFahrenheitUnit

Returns a HealthKit unit for measuring temperature in degrees Fahrenheit.

+ kelvinUnit

Returns a HealthKit unit for measuring temperature in kelvins.

Constructing Hearing Sensitivity Units

+ decibelHearingLevelUnit

Returns a HealthKit unit for measuring the intensity of a sound.

Constructing Frequency Units

+ hertzUnit

Returns a HealthKit unit for measuring frequency in hertz.

+ hertzUnitWithMetricPrefix:

Returns a HealthKit unit for measuring frequency in hertz with the provided prefix.

Constructing Electrical Conductance Units

+ siemenUnit

Returns a HealthKit unit for measuring electrical conductance in siemens.

+ siemenUnitWithMetricPrefix:

Returns a HealthKit unit for measuring electrical conductance, using siemen units with the provided prefix.

Constructing Pharmacology Units

+ internationalUnit

Returns a HealthKit unit that measures the amount of a biologically active substance in international units (IU).

Constructing Scalar Units

+ countUnit

Returns a HealthKit unit for measuring counts.

+ percentUnit

Returns a HealthKit unit for measuring percentages.

Performing Unit Math

- unitMultipliedByUnit:

Creates a complex unit by multiplying the receiving unit with another unit.

- unitDividedByUnit:

Creates a complex unit by dividing the receiving unit by another unit.

- unitRaisedToPower:

Creates a complex unit by raising the unit to the given power.

- reciprocalUnit

Returns a complex unit representing the unit’s reciprocal.

Constants

HKMetricPrefix

Prefixes that can be added to SI units to change the order of magnitude.

Relationships

Inherits From

See Also

Units and Quantities

Defining and Converting Units and Quantities

Create and convert units and quantities.

HKQuantity

An object that stores a value for a given unit.

HKMetricPrefix

Prefixes that can be added to SI units to change the order of magnitude.