Swift should I switch?

31

Transcript of Swift should I switch?

@wolfgang_dammWolfgang Damm CTO & Co-Founder

[email protected] www.pocket-lifestyle.com

SwiftShould I use it for production?

Current State• TIOBE Index of language popularity

• Swift #27, increasing

• Objective-C #4, declining

• Github number of active repositories

• Swift #18, growing

• Objective-C #11, flatData as of February 2015

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html http://githut.info/

Swift 1.2

• Xcode 6.3 Beta

• Faster builds & executables

• Better compiler diagnostics

• Stability

• and changes to the language!

as! for failable casts

if let a = a, b = b, c = c {

Nullability Annotations

enums export to Objective-C

Deferred initialisation of let constants

Set

So is it ready for prime time?

Duolingo Test Center• New App written in Swift

• 3 month(1 dev, design/backend inplace)

+ Value types, custom operators

+ Stronger, static type system, with type inference

+ Generics especially for typesafe collections

Duolingo Test Center

- Tooling: Xcode, crashes, very slow code completion, basically no debugger, unstable/unreliable syntax highlighting (got better)

- Swift language changes. Known from the beginning, in retrospect only little time spent on keeping source up to date

- Incomprehensible compiler errors

Duolingo Test Center

• Crash rate ~0.2% (crashes/downloads) mostly in Objective-C third party library

• Swift eased process of building a solid architecture. Eliminating classes of bugs by design (e.g. Swift’s type system)

@brentsimmons ObjC: “I am laughing out loud”

Swift: "LOL"

@brentsimmons• Harder on 2nd look

• optionals, generics, and tuples, value vs reference

• functional design patterns

• strict type safety

• issue interoperation with Objective-C

• “Swift is happening.”

Random Thoughts from Developers

• Common internal libraries, not rewriting just to be Swift

• Sometimes interacting with Cocoa API’s harder than thought

• Strict typing is a killer feature (finds bugs during compile time)

So is it ready for prime time?

Yes it is!

Our take aways• Future of iOS will be Swift

• New code written in Swift

• Rewriting only were it makes sense (lot of code changes, restructuring)

• Know Swift AND Objective-C

• Swift uses different patterns

• Hard to follow good patterns when interfacing with Objective-C

Experience

Experience• Compiler bugs: crashes instead of error

• Renew Certificate, otherwise it crashes submitted build

• At first slower when writing code, but learning fast

• Choice between Objective-C vs Swift patterns

• Cocoapods support is still beta

• cocoapods --pre installs 1.0.36(beta)

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => ‘xcode-6.3'

pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'xcode6.3'

Favourite Swift Way

enum Router: URLStringConvertible { static let baseURLString = "http://example.com"

case Root case User(String) case Post(Int, Int, String)

// MARK: URLStringConvertible

var URLString: String { let path: String = { switch self { case .Root: return "/" case .User(let username): return "/users/\(username)" case .Post(let year, let month, let title): let slug = title.stringByReplacingOccurrencesOfString(" ", withString: "-").lowercaseString return "/\(year)/\(month)/\(slug)" } }()

return Router.baseURLString + path } }

Enum with associated value and computed property

Learn Swift• Read “The Swift Programming Language” by Apple

• thatthinginswift.com

• swiftdoc.org

• learnswift.tips

• Start coding in Swift!

• github.com/raywenderlich/swift-style-guide

My experience learning Swift

• Functional Programming is different

• Force yourself to using good practices. Make use of strict types. Which is hard.

• Harder to define public interface (no header). Standard access modifier is internal. Also makes testing harder.

Single most hardest thing in Swift?

;

@wolfgang_dammWolfgang Damm CTO & Co-Founder

[email protected] www.pocket-lifestyle.com