---
title: HKUnit
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkunit
---

# HKUnit

A class for managing the units of measure within HealthKit.

## Declaration

```swift
class HKUnit
```

## Mentioned in

Defining and converting units and quantities

## Overview

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. note: Number formatters that use units (for example, EnergyFormatter, LengthFormatter, and MassFormatter) use a custom enumeration to specify their units. For example, the EnergyFormatter class uses the EnergyFormatter.Unit enum. The HKUnit class provides several methods to translate between the formatter enumerations and the HealthKit units. For more information, see Working with formatter units. Using Units As with many HealthKit classes, don’t subclass the HKUnit class. 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

- [init(from:)](healthkit/hkunit/init(from:)-9qont.md)
- [unitString](healthkit/hkunit/unitstring.md)
- [isNull()](healthkit/hkunit/isnull().md)

### Working with formatter units

- [energyFormatterUnit(from:)](healthkit/hkunit/energyformatterunit(from:).md)
- [init(from:)](healthkit/hkunit/init(from:)-1j1pq.md)
- [lengthFormatterUnit(from:)](healthkit/hkunit/lengthformatterunit(from:).md)
- [init(from:)](healthkit/hkunit/init(from:)-55e1u.md)
- [massFormatterUnit(from:)](healthkit/hkunit/massformatterunit(from:).md)
- [init(from:)](healthkit/hkunit/init(from:)-7h2li.md)

### Constructing mass units

- [gram()](healthkit/hkunit/gram().md)
- [gramUnit(with:)](healthkit/hkunit/gramunit(with:).md)
- [ounce()](healthkit/hkunit/ounce().md)
- [pound()](healthkit/hkunit/pound().md)
- [stone()](healthkit/hkunit/stone().md)
- [moleUnit(withMolarMass:)](healthkit/hkunit/moleunit(withmolarmass:).md)
- [moleUnit(with:molarMass:)](healthkit/hkunit/moleunit(with:molarmass:).md)
- [HKUnitMolarMassBloodGlucose](healthkit/hkunitmolarmassbloodglucose.md)

### Constructing length units

- [meter()](healthkit/hkunit/meter().md)
- [meterUnit(with:)](healthkit/hkunit/meterunit(with:).md)
- [inch()](healthkit/hkunit/inch().md)
- [foot()](healthkit/hkunit/foot().md)
- [yard()](healthkit/hkunit/yard().md)
- [mile()](healthkit/hkunit/mile().md)

### Constructing volume units

- [liter()](healthkit/hkunit/liter().md)
- [literUnit(with:)](healthkit/hkunit/literunit(with:).md)
- [fluidOunceUS()](healthkit/hkunit/fluidounceus().md)
- [fluidOunceImperial()](healthkit/hkunit/fluidounceimperial().md)
- [cupUS()](healthkit/hkunit/cupus().md)
- [cupImperial()](healthkit/hkunit/cupimperial().md)
- [pintUS()](healthkit/hkunit/pintus().md)
- [pintImperial()](healthkit/hkunit/pintimperial().md)

### Constructing pressure units

- [pascal()](healthkit/hkunit/pascal().md)
- [pascalUnit(with:)](healthkit/hkunit/pascalunit(with:).md)
- [millimeterOfMercury()](healthkit/hkunit/millimeterofmercury().md)
- [inchesOfMercury()](healthkit/hkunit/inchesofmercury().md)
- [centimeterOfWater()](healthkit/hkunit/centimeterofwater().md)
- [atmosphere()](healthkit/hkunit/atmosphere().md)
- [decibelAWeightedSoundPressureLevel()](healthkit/hkunit/decibelaweightedsoundpressurelevel().md)

### Constructing time units

- [second()](healthkit/hkunit/second().md)
- [secondUnit(with:)](healthkit/hkunit/secondunit(with:).md)
- [minute()](healthkit/hkunit/minute().md)
- [hour()](healthkit/hkunit/hour().md)
- [day()](healthkit/hkunit/day().md)

### Constructing energy units

- [joule()](healthkit/hkunit/joule().md)
- [jouleUnit(with:)](healthkit/hkunit/jouleunit(with:).md)
- [kilocalorie()](healthkit/hkunit/kilocalorie().md)
- [largeCalorie()](healthkit/hkunit/largecalorie().md)
- [smallCalorie()](healthkit/hkunit/smallcalorie().md)
- [calorie()](healthkit/hkunit/calorie().md)

### Constructing power units

- [watt()](healthkit/hkunit/watt().md)
- [wattUnit(with:)](healthkit/hkunit/wattunit(with:).md)

### Constructing temperature units

- [degreeCelsius()](healthkit/hkunit/degreecelsius().md)
- [degreeFahrenheit()](healthkit/hkunit/degreefahrenheit().md)
- [kelvin()](healthkit/hkunit/kelvin().md)

### Constructing hearing sensitivity units

- [decibelHearingLevel()](healthkit/hkunit/decibelhearinglevel().md)

### Constructing frequency units

- [hertz()](healthkit/hkunit/hertz().md)
- [hertzUnit(with:)](healthkit/hkunit/hertzunit(with:).md)

### Constructing vision units

- [diopter()](healthkit/hkunit/diopter().md)
- [prismDiopter()](healthkit/hkunit/prismdiopter().md)

### Constructing angle units

- [degreeAngle()](healthkit/hkunit/degreeangle().md)
- [radianAngle()](healthkit/hkunit/radianangle().md)
- [radianAngleUnit(with:)](healthkit/hkunit/radianangleunit(with:).md)

### Constructing electrical conductance units

- [siemen()](healthkit/hkunit/siemen().md)
- [siemenUnit(with:)](healthkit/hkunit/siemenunit(with:).md)

### Electrical potential difference

- [volt()](healthkit/hkunit/volt().md)
- [voltUnit(with:)](healthkit/hkunit/voltunit(with:).md)

### Constructing pharmacology units

- [internationalUnit()](healthkit/hkunit/internationalunit().md)

### Constructing scalar units

- [count()](healthkit/hkunit/count().md)
- [percent()](healthkit/hkunit/percent().md)

### Performing unit math

- [unitMultiplied(by:)](healthkit/hkunit/unitmultiplied(by:).md)
- [unitDivided(by:)](healthkit/hkunit/unitdivided(by:).md)
- [unitRaised(toPower:)](healthkit/hkunit/unitraised(topower:).md)
- [reciprocal()](healthkit/hkunit/reciprocal().md)

### Constants

- [HKMetricPrefix](healthkit/hkmetricprefix.md)

### Initializers

- [init(coder:)](healthkit/hkunit/init(coder:).md)
- [init(fromEnergyFormatterUnit:)](healthkit/hkunit/init(fromenergyformatterunit:).md)
- [init(fromLengthFormatterUnit:)](healthkit/hkunit/init(fromlengthformatterunit:).md)
- [init(fromMassFormatterUnit:)](healthkit/hkunit/init(frommassformatterunit:).md)
- [init(fromString:)](healthkit/hkunit/init(fromstring:).md)

### Type Methods

- [appleEffortScore()](healthkit/hkunit/appleeffortscore().md)
- [lux()](healthkit/hkunit/lux().md)
- [luxUnit(with:)](healthkit/hkunit/luxunit(with:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Units and quantities

- [Defining and converting units and quantities](healthkit/defining-and-converting-units-and-quantities.md)
- [HKQuantity](healthkit/hkquantity.md)
- [HKMetricPrefix](healthkit/hkmetricprefix.md)
