Open
Description
I've defined a custom Dimension to represent the pace.
public final class UnitPace: Dimension {
public static let secondsPerMeter = UnitPace(
symbol: "s/m",
converter: UnitConverterLinear(coefficient: 1)
)
}
extension Measurement where UnitType == UnitPace {
public init(
minutes: Int,
seconds: Int,
unit: UnitPace
) {
let value = Double(minutes) + Double(seconds) / 60
self.init(
value: value,
unit: unit
)
}
}
I want to format a Measurement<UnitPace>
so it can be shown in the UI.
let paceMeasurement: Measurement<UnitPace> = Measurement<UnitPace>(
minutes: 5,
seconds: 30,
unit: .secondsPerMeter
)
Text(paceMeasurement.formatted(.measurement(width: .narrow, numberFormatStyle: .number.precision(.fractionLength(0...1)))) ?? "-")
// "... s/m" is displayed
How can I specify the localised strings for the different UnitStyle
(short, medium, long) / UnitWidth
(wide, abbreviated, narrow) to use?