Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created January 17, 2021 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/d2f4b50e6ccf6b703baed749356bccde to your computer and use it in GitHub Desktop.
Save laevandus/d2f4b50e6ccf6b703baed749356bccde to your computer and use it in GitHub Desktop.
class UnitBanana: Dimension {
override static func baseUnit() -> Self {
return UnitBanana.banana as! Self
}
static let banana = UnitBanana(symbol: "bana", converter: UnitConverterLinear(coefficient: 1.0))
}
let formatter = MeasurementFormatter()
formatter.unitOptions = .providedUnit
print(formatter.string(from: Measurement(value: 2, unit: UnitBanana.banana)))
// 2 bana
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment