ios8 - Extension sample using Swift -
i have gone through new ios8 , read extension. 1 please me sample creating extension ? in advance
this example adds 5 computed instance properties swift’s built-in double type, provide basic support working distance units:
extension double { var km: double { return self * 1_000.0 } var m: double { return self } var cm: double { return self / 100.0 } var mm: double { return self / 1_000.0 } var ft: double { return self / 3.28084 } } let oneinch = 25.4.mm println("one inch \(oneinch) meters") // prints "one inch 0.0254 meters" let threefeet = 3.ft println("three feet \(threefeet) meters") // prints "three feet 0.914399970739201 meters
excerpt from: apple inc. “the swift programming language.” ibooks. https://itun.es/ca/jeuh0.l
Comments
Post a Comment