Transitioning to Swift

Jonathan Lehr
September 04, 2014

Transitioning to Swift

From a presentation at a CocoaHeads DC meeting, September 4, 2014. Provides a brief overview of potential benefits, hurdles, and pitfalls for Objective-C development teams to consider as they contemplate adopting the Swift programming languages.

Jonathan Lehr

September 04, 2014

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

22 slides
  1. About Objects 1818 Library Street | 5th Floor | Reston,

    VA 20190 main: 571-346-7544 | www.aboutobjects.com Enterprise Consulting • iOS Developer Training Transitioning to Swift
  2. About Objects Jonathan Lehr Founder, CEO ! • Developer, author,

    speaker. • 20+ years Objective-C and Java, including 7 years on iOS. 1818 Library Street | 5th Floor | Reston, VA 20190 main: 571-346-7544 | www.aboutobjects.com iOS Developer Training • Enterprise iOS Development
  3. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    About Objects • iOS developer training ‣ Reston, Cupertino, and Boulder • Enterprise development projects (Fortune 500) ‣ iOS and Android ‣ Cloud and Big Data 3
  4. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Problems with C/Obj-C • Usability • Correctness • Predictability • Performance 4
  5. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Suitability • Goal of Apple’s Swift team—design a new language suitable for: ‣ Scripting ‣ Kernel-level programming ‣ Cocoa development (#1 priority) 5
  6. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Playgrounds and REPL • Great environments for learning, experimentation • DEMOs: ‣ Dynamism Playground ‣ Graphics Playground ‣ Balloons Playground (optional) 6
  7. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Current Status • GM release this Fall • ABI not currently stable • Some language features still in flux • Playgrounds have Yosemite dependencies 7
  8. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Classes and Structures • Value types vs. reference types • Structures can have methods as well as properties • Swift classes don’t respond to NSObject messages unless they’re subclasses of NSObject • Still can leverage dynamic dispatch via @objc and dynamic 9
  9. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Extensions • Similar to Objective-C categories • Extend ‘types’ rather than classes • Can add computed properties as well as methods to structs 10
  10. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Optionals • nil has a different meaning — absence of any value • Optional types may be either nil or have a value • You have to ‘unwrap’ optional values ‣ An Optional is actually a enum with two members, some and none. 11
  11. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Other Features • Enumerations • Pattern matching • Generics 12
  12. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Background • Concerns and questions that came up regarding some of our current projects • Cerner Millenium+ • NFL Now 14
  13. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Current Status • Language still in beta • Great time to experiment and give feedback to Apple • Not a great time to use for mission-critical projects 15
  14. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Existing ObjC Codebases • Will be with us for a long time • Will need to be enhanced • This includes Apple’s codebases 16
  15. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Cocoa Development • High priority for the compiler engineering team • Some features still missing ‣ For example, some of the UIAppearance API • For the most part though, Swift works quite well 17
  16. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Pitfalls? • Overdoing customization of types and operators • Nobody has “years of experience” in Swift ‣ Many pitfalls and best practices have yet to be determined ‣ We don’t know what we don’t know • Being too eager to adopt quickly, and running into unforeseen problems 18
  17. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Recommendations • Wait for GM release • Ideally, begin with new classes in existing projects ‣ Think, adding a new scene to a storyboard • Consider (with caution) to use as primary language for new projects after GM release ‣ Best to experiment on lower-priority projects 19
  18. © Copyright 2014, About Objects, Inc. All rights reserved worldwide.

    Example App • Storyboard-based iOS app • Includes ‘bridged’ ObjC classes • DEMO: SwiftReadingList-Bridged 20
  19. © Copyright 2007–2013, About Objects, Inc. All rights reserved worldwide.

    For Further Information 21 AO Website http://www.aboutobjects.com AO on LinkedIn http://www.linkedin.com/company/856293 Contact [email protected] Apple Swift Resources https://developer.apple.com/swift/blog/

More Decks by Jonathan Lehr

Other Decks in Programming