Dive Into Swift

Preview:

Citation preview

Dive Into SwiftKristijan Frankovic

Swift Powerful, intuitive, safe, fast, interactive, concise… iOS, OS X, watchOS Object-oriented, functional, static, strong typing… Beta – June 2014 1.0 – September 2014 1.2 – April 2015 2.1 – October 21, 2015

Swift 1.2 vs 2.1 Xcode 6 (1.2) -> Xcode 7 (2.x) – bunch of syntax errors Migration assistant (Edit / Convert / To latest println -> print Join (“”, components) -> components.joinWithSeparator(“”)

Error handling (1.2)var error: NSError?var something = context!.executeFetchRequest(request, error: &error)

Error handling (2.x)do {

var something = context.executeFetchRequest(request)} catch let error as NSError {

// do something with error}

Swift vs Objective-C Objective-C:Person *franc = [[Person alloc] initWithName:@"Kristijan"];[franc sayHello];

var franc = Person(name:"Kristijan")franc.sayHello()

Swift:

Objective-C Compatibility Bridging

iOS was developed in Objective-C Virtually all iOS API is accessible seamlessly from Swift Special data types – easier use of iOS API from Obj-c

NSString, NSArray, NSDictionary, NSNumber (int, float, double, bool) Import Objective-C code in Swift project and vice-versa

DemoDemo code is available at GitHub Gist:

https://gist.github.com/kfrankovic/61da4e0210e4861603e1