DistanceFormatter
A formatter that provides localized representations of distance units and measurements.
This class is limited to UnitLength
and its behavior is more specific to distances than MeasurementFormatter
. By default, the class automatically localizes and rounds the measurement using Measurement.localized(into:)
and Locale.nationalizedCurrent
. Measurements can be formatted into either strings or attributed strings.
-
-
Options for choosing and formatting the unit.
Seealso
MeasurementFormatter.unitOptions
-
The unit style.
Seealso
MeasurementFormatter.unitStyle
-
The locale that determines the chosen unit, name of the unit, and number formatting.
Seealso
MeasurementFormatter.locale
-
The underlying measurement formatter.
-
-
-
Creates and returns a localized, formatted string representation of the given distance in meters.
The distance is converted from meters to the most appropriate unit based on the locale and quantity.
Seealso
MeasurementFormatter.string(from:)
-
Creates and returns a localized, formatted attributed string representation of the given distance in meters.
The distance is converted from meters to the most appropriate unit based on the locale and quantity.
NSAttributedString.Key.quantity
is applied to the range representing the quantity. For example, the “5” in “5 km” has a quantity attribute set to 5. -
-