0

I have gone through new iOS8 and read about the Extension. Could any one please help me any sample for creating extension ? Thanks in advance

Andrew
  • 15,357
  • 6
  • 66
  • 101
SRI
  • 1,514
  • 21
  • 39
  • Could you please tell me what is the reason for downvoting? – SRI Jun 09 '14 at 08:49
  • Do you mean the extension in the swift language or the extensions in iOS 8? If you mean the extension in iOS 8 watch the relevant WWDC-Videos. – Ben Jun 09 '14 at 14:53

1 Answers1

1

This example adds five computed instance properties to Swift’s built-in Double type, to provide basic support for working with 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 is \(oneInch) meters")
// prints "One inch is 0.0254 meters"
let threeFeet = 3.ft
println("Three feet is \(threeFeet) meters")
// prints "Three feet is 0.914399970739201 meters

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/ca/jEUH0.l

David Skrundz
  • 13,067
  • 6
  • 42
  • 66