Download - Swift 2
![Page 1: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/1.jpg)
A short introduction to Swift 2
![Page 2: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/2.jpg)
syntax goodies
![Page 3: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/3.jpg)
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)
![Page 4: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/4.jpg)
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
![Page 5: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/5.jpg)
guard
func someFunction(value: Int?){ guard let value = value else {return} let calc = 1 + value }
![Page 6: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/6.jpg)
defer
func awesomeStuff() { someCalculation() defer { cleanUp() } otherStuff() }
![Page 7: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/7.jpg)
available
if #available(iOS 8.0, *) { // new features from iOS 8 } else { // a fallback feature }
![Page 8: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/8.jpg)
error handling
![Page 9: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/9.jpg)
calling a throwing function
do { try otherStuff() } catch let error { // handle the error }
![Page 10: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/10.jpg)
throw an error
func otherStuff() throws { throw NSError(domain: "OutOfIdeasException",
code: 404, userInfo: nil) }
![Page 11: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/11.jpg)
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 } }
![Page 12: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/12.jpg)
force try
enum Error: ErrorType { case NetworkFailed case DeviceOverheated }
func otherStuff() throws { throw Error.NetworkFailed }
func awesomeStuff() { try! otherStuff() }
![Page 13: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/13.jpg)
protocol extensions
![Page 14: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/14.jpg)
default implementationsprotocol 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()
![Page 15: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/15.jpg)
protocol oriented programming
https://developer.apple.com/videos/wwdc/2015/?id=408
![Page 16: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/16.jpg)
but there is one more thing
![Page 17: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/17.jpg)
Swift becoming open source
![Page 18: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/18.jpg)
• 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.
![Page 20: Swift 2](https://reader031.vdocuments.us/reader031/viewer/2022032505/55c5a739bb61eb1b2a8b4803/html5/thumbnails/20.jpg)
https://github.com/nestproject/NestBox
import NestBox
let server = serve("127.0.0.1", 8080) { environ in return ("200 OK", [], "Hello World!") }
server()
Nest