我不确定如何使用测量来获取单位的全名。例如“千米”而不是“千米”。
let measurement = Measurement(value: 50, unit: UnitLength.meters)
let convertedMeasurement = measurement.converted(to: UnitLength.kilometers)
let value = convertedMeasurement.value // 0.05
let unitSymbol = convertedMeasurement.unit.symbol // km
let unit = convertedMeasurement.unit.? // I expect the output to be "kilometers"
答案 0 :(得分:2)
为了获得单位的全名,您可以使用MeasurementFormatter
,如下所示:
let formatter = MeasurementFormatter()
formatter.unitStyle = .long
let unit = formatter.string(from: convertedMeasurement.unit) //"kilometers"