In Swift when I create custom units I can only define one symbol. With the built in units there can be short, medium and long units. How do you set the other unit styles for a custom unit?
extension UnitEnergy {
static let footPounds = UnitEnergy(symbol: "ft-lbs", converter: UnitConverterLinear(coefficient: 1))
}
var test = Measurement<UnitEnergy>( value: 10, unit: .footPounds)
var formatter = MeasurementFormatter()
formatter.locale = Locale(identifier: "es")
formatter.unitStyle = .short
print( formatter.string(from: test))
formatter.unitStyle = .medium
print( formatter.string(from: test))
formatter.unitStyle = .long
print( formatter.string(from: test))
formatter.unitOptions = .providedUnit
formatter.unitStyle = .short
print( formatter.string(from: test))
formatter.unitStyle = .medium
print( formatter.string(from: test))
formatter.unitStyle = .long
print( formatter.string(from: test))
Output:
10 J
10 J
10 julios
10 ft-lbs
10 ft-lbs
10 ft-lbs