Created
July 11, 2018 03:07
-
-
Save AdrianBinDC/b6fb3cf4c198366073053fa56ac99152 to your computer and use it in GitHub Desktop.
Convert distances from one unit of measurement to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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