Skip to content

Instantly share code, notes, and snippets.

View dtorres's full-sized avatar

Diego Torres dtorres

View GitHub Profile
@dtorres
dtorres / ApproximateConversion.swift
Last active May 17, 2020 10:08 — forked from ekurutepe/ApproximateConversion.swift
Conversions in Measurement too accurate for you? Here take this…
import Foundation
extension Measurement where UnitType: UnitLength {
func approximatelyConverted(to otherUnit: UnitType) -> Measurement<UnitType> {
switch (unit, otherUnit) {
case (UnitLength.meters, UnitLength.feet):
return Measurement(value: value * 3, unit: otherUnit)
case (UnitLength.feet, UnitLength.meters):
return Measurement(value: value * 3 / 10, unit: otherUnit)
default: