Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active January 17, 2021 05:01
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/fe76115346fd5c7aafca0a9f55c0be31 to your computer and use it in GitHub Desktop.
Save laevandus/fe76115346fd5c7aafca0a9f55c0be31 to your computer and use it in GitHub Desktop.
let formatter = MeasurementFormatter()
let unitStyles: [Formatter.UnitStyle] = [.short, .medium, .long]
for unitStyle in unitStyles {
formatter.unitStyle = unitStyle
let measurement = Measurement(value: 9.8, unit: UnitAcceleration.gravity)
print(formatter.string(from: measurement))
}
// Prints:
// 9.8Gs
// 9.8 G
// 9.8 g-force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment