Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Swift 2

858 views

Published on

Slides on news in Swift 2 from a presentation at swift.berlin.

Published in: Software
  • Be the first to comment

Swift 2

  1. 1. A short introduction to Swift 2
  2. 2. syntax goodies
  3. 3. Swift 1.2 - Objective-C generics - Pattern Matching - Availability Checking - do/while is now repeat - unit testing via @testable - Markdown support for documentation
 (including images)
  4. 4. nested generic value types public enum Result<T> { case Success(T) case Error(NSError) } public enum Result<T> { case Success(Box<T>) case Error(NSError) } Swift 1.2 Swift 2
  5. 5. guard func someFunction(value: Int?){ guard let value = value else {return} let calc = 1 + value }
  6. 6. defer func awesomeStuff() { someCalculation() defer { cleanUp() } otherStuff() }
  7. 7. available if #available(iOS 8.0, *) { // new features from iOS 8 } else { // a fallback feature }
  8. 8. error handling
  9. 9. calling a throwing function do { try otherStuff() } catch let error { // handle the error }
  10. 10. throw an error func otherStuff() throws { throw NSError(domain: "OutOfIdeasException", code: 404, userInfo: nil) }
  11. 11. throw a custom error enum Error: ErrorType { case NetworkFailed case DeviceOverheated } func otherStuff() throws { throw Error.NetworkFailed } func awesomeStuff() { do { try otherStuff() } catch Error.NetworkFailed { // handle the error } catch { // unspecific error } }
  12. 12. force try enum Error: ErrorType { case NetworkFailed case DeviceOverheated } func otherStuff() throws { throw Error.NetworkFailed } func awesomeStuff() { try! otherStuff() }
  13. 13. protocol extensions
  14. 14. default implementations protocol Drinkable { func drink() } struct Beer: Drinkable { } struct Mate: Drinkable { func drink() { print("Mate specific drinking.") } } extension Drinkable { func drink() { print("Time to drink!") } } Beer().drink()
  15. 15. protocol oriented programming https://developer.apple.com/videos/wwdc/2015/?id=408
  16. 16. but there is one more thing
  17. 17. Swift becoming open source
  18. 18. • Swift source code will be released under an OSI-approved permissive license. • Contributions from the community will be accepted — and encouraged. • At launch we intend to contribute ports for OS X, iOS, and Linux. • Source code will include the Swift compiler and standard library.
  19. 19. Nest https://github.com/nestproject
  20. 20. https://github.com/nestproject/NestBox import NestBox let server = serve("127.0.0.1", 8080) { environ in return ("200 OK", [], "Hello World!") } server() Nest
  21. 21. Thank you. @JensRavens github.com/jensravens

×