A short introduction to
Swift 2
syntax goodies
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)
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
guard
func someFunction(value: Int?){
guard let value = value else {return}
let calc = 1 + value
}
defer
func awesomeStuff() {
someCalculation()
defer { cleanUp() }
otherStuff()
}
available
if #available(iOS 8.0, *) {
// new features from iOS 8
} else {
// a fallback feature
}
error handling
calling a throwing function
do {
try otherStuff()
} catch let error {
// handle the error
}
throw an error
func otherStuff() throws {
throw NSError(domain: "OutOfIdeasException",
code: 404, userInfo: nil)
}
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
}
}
force try
enum Error: ErrorType {
case NetworkFailed
case DeviceOverheated
}
func otherStuff() throws {
throw Error.NetworkFailed
}
func awesomeStuff() {
try! otherStuff()
}
protocol extensions
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()
protocol oriented
programming
https://developer.apple.com/videos/wwdc/2015/?id=408
but there is
one more thing
Swift becoming
open source
• 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.
Nest
https://github.com/nestproject
https://github.com/nestproject/NestBox
import NestBox
let server = serve("127.0.0.1", 8080) { environ in
return ("200 OK", [], "Hello World!")
}
server()
Nest
Thank you.
@JensRavens
github.com/jensravens

Swift 2