Contents

usage

The intended purpose of the formatted measurement.

Declaration

var usage: MeasurementFormatUnitUsage<UnitType>?

Discussion

You can use the usage property to specify the intended purpose of the formatted measurement. The default option, general, formats the measurement with the default unit for the current locale. The asProvided option formats the measurement using the specified unit, ignoring the unit that the locale uses.

The following example shows a formatted temperature using the default unit for the en_US locale and using a provided Celsius unit:

let temperature = Measurement<UnitTemperature>(value: 36.8, unit: .celsius)
temperature.formatted()
// 98°F

temperature.formatted(.measurement(width: .abbreviated, usage: .asProvided))
// 36.8°C

All unit types have general and asProvided options. Some subclasses have additional options, such as the following:

UnitTemperature

  • person

  • weather

UnitLength

  • person

  • personHeight

  • road

UnitEnergy

  • food

  • workout

UnitMass

  • personWeight

See Also

Modifying a measurement format style