Когда я запускаю следующий код на игровой площадке, отформатированная строка возвращается как нуль. Что мне не хватает в производном пользовательском классе измерений?Использование MeasurementFormatter с производным модулем
open class UnitFlowRate : Dimension {
open override static func baseUnit() -> UnitFlowRate { return self.metricTonsPerHour }
static let shortTonsPerHour = UnitFlowRate(symbol: NSLocalizedString("stph", comment: "short tons per hour"), converter: UnitConverterLinear(coefficient: 1))
static let metricTonsPerHour = UnitFlowRate(symbol: NSLocalizedString("mtph", comment: "metric tons per hour"), converter: UnitConverterLinear(coefficient: 2))
}
var measureCustom = Measurement<UnitFlowRate>(value: 12.31, unit: .shortTonsPerHour)
var measureSystem = Measurement<UnitLength>(value: 12.31, unit: .inches)
var formatter = MeasurementFormatter()
var measureStringCustom = formatter.string(for: measureCustom)
var measureStringSystem = formatter.string(for: measureSystem)
print(measureCustom) // This works
print(measureSystem) // This works
print(measureStringCustom) // This is nil - Why?
print(measureStringSystem) // This works
Выход:
12.31 stph
12.31 in
nil
Optional("0 mi")