Pro Yearly is on sale from $80 to $50! »

Production Swift

0ebf471a3ae8df42a84f93a7efbbdbd0?s=47 Ash Furrow
February 06, 2015

Production Swift

In this talk, I use my recent real-world experience with Swift as a case study in an evaluation of Swift's production readiness. Take advantage of the lessons we learned to make the best decisions about Swift in your project.

Video is up here: http://www.thedotpost.com/2015/02/ash-furrow-swift-in-production

0ebf471a3ae8df42a84f93a7efbbdbd0?s=128

Ash Furrow

February 06, 2015
Tweet

Transcript

  1. Production Swift Ash Furrow

  2. None
  3. Objective-C

  4. Agenda 1. Swift is Awesome 2. Tools are Immature 3.

    Be Informed
  5. Swift is Different

  6. How is it different? • Static vs. Dynamic • Prefers

    immutability • Encourages functional programming • Safe (well, safer) • Experimentation via Playgrounds
  7. Optional Protocol Methods @protocol MyProtocol <NSObject> @required - (void)doSomethingNecessary; @optional

    - (void)doSomethingOptional; @end
  8. Optional Protocol Methods protocol MyProtocol { func doSomethingNecessary() optional func

    doSomethingOptional() } // Compiler Error!
  9. Optional Protocol Methods func doSomethingNecessary() optional func doSomethingOptional() } @objc

    protocol MyProtocol {
  10. Objective-C Interoperability • Interoperability comes at the cost of Swift’s

    purity • We loose a lot of safety • Don’t just add @objc because it’ll make code compile
  11. Swift is Better

  12. Objective-C Hurts Me if (indexPath.section == 0) { if (indexPath.row

    == 0) { } else if (indexPath.row == 1) { 
 } else if ... } else if (indexPath.section == 1) { if (indexPath.row == 0) { } else if (indexPath.row == 1) { 
 } else if ... } else if ...
  13. Pattern Matching switch (indexPath.section, indexPath.row) { case (0, 0): case

    (0, 1): case (1, 0): case (1, 1): default: // nop }
  14. Pattern Matching case (let section, 0) where section % 2

    == 0: case (0, let row): case let (0, row) where validate(row):
  15. Self-Evaluating Lazy Closures class MySweetViewController: UIViewController { lazy var button:

    UIButton = { let button = UIButton.buttonWithType(.System) // configure button return button }() }
  16. And many more … enums closures tuples generics compile-time awesomeness

    saved a kitten from a fire went to highschool prom with me function currying functions are closures array.sort(<) better terroir immutability by default type inference discovered penicillin operator overloading clear mutability syntax native collections REPL multiple return types concise pattern-matching
  17. Tools are Immature

  18. Apple Tools • Xcode, clang, Playgrounds, SourceKit, code signing, frameworks

    … • All are unstable • Causes frustrations • Causes delays • Causes hair loss
  19. github.com/artsy/eidolon

  20. Open Source by Default

  21. Using Swift doubled our development time

  22. “We don’t expect to make our deadline.”

  23. Eidolon Problems • Enterprise code signing issues with Xcode 6.1

    • Compiler segfaults with optimizations enabled • Constant Xcode/SourceKit crashes • Unit testing problems
  24. None
  25. Burnout

  26. We made our deadline

  27. Eidolon Awesomeness • We helped pioneer a new way of

    writing iOS software • Created many new libraries, tools, and resources • Used others’ new tools and contributed bug reports and fixes • Learnt a tonne, shared with others
  28. Apple Tools • Someday soon, these will be ready for

    everyday use • But not today • You will have unanticipated problems • There will be no known solutions or workarounds • Until then, use with caution
  29. 3rd Party Tools • CocoaPods 0.36 has support for Swift

    • Tremendous amount of open source effort • Pre-1.0, use with caution • Carthage is new but promising • Pre-1.0, use with caution
  30. Be Informed

  31. Making a Choice • What’s your aversion to risks? •

    How hard is your deadline? • Why are you building something? • How open is your team to learning a new language?
  32. Why Bother?

  33. Swifxpert Become a

  34. Blog

  35. Risks Rewards vs.

  36. Be Aware • Don’t be afraid to revisit your decision

    • It’s OK to switch back to Objective-C
  37. Recap Swift is Awesome Tools are Immature Be Informed

  38. Make an informed choice. So start now. You need to

    know Swift to be informed.