Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nubbel/33057d8d241aa1676ad1 to your computer and use it in GitHub Desktop.
Save nubbel/33057d8d241aa1676ad1 to your computer and use it in GitHub Desktop.
import Foundation
struct Meter {
var value: Double
init(_ value: Double) {
self.value = value
}
var mm: Double { return value * 1000.0 }
var km: Double { return value / 1000.0 }
}
extension Meter : FloatLiteralConvertible {
static func convertFromFloatLiteral(value: Double) -> Meter {
return Meter(value)
}
}
let meter: Meter = 100_000.0
meter.mm // => 100,000,000.0
meter.km // => 100.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment