Contents

unitOptions

The options for how the unit is formatted.

Declaration

var unitOptions: MeasurementFormatter.UnitOptions { get set }

Discussion

You can set this property to ensure that the formatter chooses the preferred unit to format for the measurement based on the formatter’s locale. For possible values, see MeasurementFormatter.UnitOptions.

If no options are specified, the formatter localizes according to the preferences of the formatter’s locale. For example, a measurement in kilocalories may be formatted as C instead of kcal, or a measurement in kilometers per hour may be formatted as miles per hour for US and UK locales, but kilometers per hour for other locales. However, if the providedUnit option is specified, a measurement with kilocalories units would be formatted as kcal, even if the locale prefers C, and a measurement with kilometersPerHour units would be formatted as kilometers per hour for US and UK locales, even though they prefer miles per hour.

See Also

Specifying the Format