Skip to content

Instantly share code, notes, and snippets.

@AdrianBinDC
Created July 11, 2018 03:07
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 AdrianBinDC/b6fb3cf4c198366073053fa56ac99152 to your computer and use it in GitHub Desktop.
Save AdrianBinDC/b6fb3cf4c198366073053fa56ac99152 to your computer and use it in GitHub Desktop.
Convert distances from one unit of measurement to another
extension Double {
func convert(from originalUnit: UnitLength, to convertedUnit: UnitLength) -> Double {
return Measurement(value: self, unit: originalUnit).converted(to: convertedUnit).value
}
}
/*
let miles = 26.2
let meters = miles.convert(from: .miles, to: .meters)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment