Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swift, why I won’t go back to Objective-C

Swift, why I won’t go back to Objective-C

By Robert van Loghem

Since Apple introduced Swift at WWDC ’14, I’ve been using the new language steadily in my new projects and existing projects. At first it was a love and mostly hate relationship. Slow compiler, slow Arrays, cryptic error messages, Signal 11 galore... it was the worst. When version 1.2 came out, most of my hate of the immature language and tools vanished and finally the benefits compared to Objective-C became very clear to me.

Robert van Loghem has been programming since he was 13 years old in Turbo Pascal, after doing over a decade of backend development in Java, and some Scala, he started developing Objective-C iOS apps in 2010 for NS and a little bit of ProRail. Now in 2015 he’s doing 100% Swift at Suitsupply.

CocoaHeadsNL

May 20, 2015
Tweet

More Decks by CocoaHeadsNL

Other Decks in Programming

Transcript

  1. S W I F T, W H Y I W O N ’ T G O
    B A C K T O O B J E C T I V E - C
    R O B E R T VA N L O G H E M - S W I F T G U Y @ S U I T S U P P LY
    T: @ S O U N D B I T E S
    E : R VA N L O G H E M @ S U I T S U P P LY. C O M

    View Slide

  2. A B O U T
    M E
    • Lots of backend in Java (’99)
    and some Scala
    • Actionscript/Javascript
    • Doing iOS since 2010 for NS,
    ProRail some small clients and
    now Suitsupply
    • Love road-cycling 100+km’s
    and tinkering with Bluetooth
    LE heart rate, power, cadence,
    speed, external displays

    View Slide

  3. M Y R U L E S
    • Let the compiler catch my mistakes
    • Concise
    • Immutability
    • It’s ok to be a little verbose
    • Good code does not need
    documentation
    • Refactor, refactor, refactor, …
    • Composition
    • Clear responsibilities
    • Embrace change

    View Slide

  4. M Y
    T O O L S
    • PaintCode
    • AppCode*
    • Crashlytics
    • parse.com
    • Cocoapods
    • Cocoacontrols
    • Dash
    • Sketch

    View Slide

  5. A B O U T
    S U I T S U P P LY
    • Doing instore sales apps
    on iPod Touches
    • Working on customer apps
    • Working on secret projects
    • need good people…who
    can’t go back to 

    Objective-C

    View Slide

  6. < 1 . 2
    ~ > 1 . 2

    View Slide

  7. “I started with Swift < 1.0 because I did some Scala
    in the past and it seemed to be the new Apple
    future”

    View Slide

  8. M A R M O T T E
    C R E A T E A C Y C L I N G A P P, T H A T U S E S S W I F T A N D B L U E T O O T H L E C O N N E C T I V I T Y
    11:11 01:43
    41 65
    31.2
    39.3
    3 164
    89

    View Slide

  9. L O V E
    • let vs var
    • Options: SomeClass?, .None, .Some(x)
    • if let x = y as? SomeClass
    • No more headers!
    • switch, case, where
    • Type inference
    • map, filter, reduce chaining
    • closures where you can remember the syntax
    • Less verbose
    • Named tuples
    • Generics

    View Slide

  10. View Slide

  11. H AT E
    • Weird compiler error
    messages
    • Slow compilation
    • Crashes…
    • if let { if let { if let }} nesting
    hell
    • Slow arrays and dictionaries
    • Symbolicated Swift crash logs

    View Slide

  12. View Slide

  13. “Then Apple started on improving Swift and
    tuning its syntax”

    View Slide

  14. “In december 2014 ~20% of the code in the NS
    Reisplanner Xtra consisted of Swift code”

    View Slide

  15. B E T W E E N
    < 1 . 0 A N D 1 . 2
    • Cumbersome but helpful
    syntax upgrades
    • private/public/internal access
    for properties
    • But after creating more Swift
    files the compiler slowed to a
    crawl…
    • Fail-able initialisers

    View Slide

  16. View Slide

  17. B U T W H AT A B O U T
    M Y T O O L S ?
    • AppCode is WAAAAY
    behind, so proper refactoring
    is a pain…
    • PaintCode catched up pretty
    quickly
    • So did Dash…

    View Slide

  18. “Swift 1.2 launched and IMHO can be used in
    production”

    View Slide

  19. “Now in since march 2015 I’ve gone 100% Swift”

    View Slide

  20. M O R E L O V E
    • The compiler became fast
    (incremental)
    • if let a = b, c = d where a ==
    • Nullability safety
    • Set
    • Default values

    View Slide

  21. View Slide

  22. “So what was the most profound improvement
    since moving to Swift?”

    View Slide

  23. “In the TestFlight Beta all my crashes are occurring
    in other frameworks”

    View Slide

  24. R U L E S I A P P LY T O S W I F T
    D E V E L O P M E N T
    • Never ever use ! with optionals unless you REALLY
    know what you are doing it’s the main source of my
    crashes
    • Use if let all over the place
    • Use generics and embrace type inference and Swift’s
    type system in general
    • Let the compiler really help you…

    View Slide

  25. S O W H AT ’ S
    N E X T ?
    • FutureKit
    • NotificationObserverKit
    • Reactive Cocoa 3.0


    View Slide

  26. View Slide

  27. View Slide

  28. “My goal is to: make everything type safe…and be
    crystal clear about my intentions”

    View Slide

  29. S W I F T , W H Y I
    W O N ’ T G O B A C K
    T O O B J E C T I V E - C
    T: @ S O U N D B I T E S
    E : R VA N L O G H E M @ S U I T S U P P LY. C O M

    View Slide