Is Swift Development Right for You?
Swift debuted at the Apple Worldwide Developers Conference (WWDC) in June 2014, offering a performance-tuned type-safe modern programming language. With features like closures, generics, type inference, and multiple return types, Swift takes Cocoa and Cocoa Touch development to a new level. In the WWDC keynote, Craig Federighi called it “Objective-C without the baggage of C.”
Now, some months later, it’s a great time to check whether or not you’re on target for adopting Swift. Is Swift right for you? And, if so, are you taking the necessary steps to bring Swift into your development arsenal? This write-up helps survey the situation.
State of the Swift
At this writing, nearly a year since Swift’s introduction, many developers are still negotiating the transition from Objective-C. Swift is now well past its 1.0 release, but it remains very much an evolving target.
Apple guarantees only binary compatibility for release versions of its language. While your built products will keep working in their targeted OS releases, the code that created them might start throwing compiler errors in successive language releases.
Does it sounds like a challenge to develop for an evolving language? It is. Fortunately, the basics of the language have more or less stabilized. The code you write today will look fundamentally similar to the code you write in a year, even if nitty-gritty specifics continue to shift.
Weigh the pros and cons as you look forward to the 2015–2016 development year.
Is Swift Right for You?
Objective-C lives. Swift’s release has not caused iOS developers to abandon Objective-C. While some—especially larger development houses with the flexibility to assign extra personnel—are testing out the waters with pure Swift projects, many independent developers have invested too much in Objective-C libraries and toolsets to start over with fresh new Swift implementations. These developers will continue with either pure Objective-C projects, or hybrid solutions that balance their current libraries with new Swift code.
Objective-C isn’t going away any time soon. For the foreseeable future, you can remain in the Objective-C world, using your familiar APIs, and avoiding the retraining, refactoring, and other costs associated with moving to a new language.
However, Swift remains an important skill for many developers to learn. Expect to see more emphasis on Swift in sample code, technical talks, and so forth. Swift delivers tangible benefits, including speed benchmarks, efficiency, and type safety. It also offers compelling language elements, like generics and tuples and compound switch statements.
Speaking from experience, it can be hard to move back from Swift-based projects to Objective-C when you’re reaching for language essentials like generics and tuples that aren’t in the older language. Swift’s modern features offer real improvements in day-to-day development.
Admittedly, the current development toolset can be maddening. Early language means early tools, and while Swift uses the same LLVM compiler as Objective-C uses, the developer-facing feedback can still feel pretty “Wild West” when it comes to error messages and debugging.
Objective-C remains a known quantity with known development costs and overhead. It may be old-fashioned and stodgy, but it’s also solid and reliable. In contrast, Swift can introduce sudden unexpected roadblocks that force you to invest time in moving past language and compiler limitations. But those time investments might be worthwhile, because Swift also delivers golden development nuggets that pay for those unexpected costs and provide a solid investment in future development.
Consider Hybrid Adoption
Moving to Swift doesn’t have to be an all-or-nothing choice. Xcode offers ways for you to transition a little at a time through mixed-language projects. Hybrid solutions allow you to call Objective-C implementations from Swift, and Swift implementations from Objective-C.
Swift uses the same compiler, ARC memory-management model, and runtime as Objective-C does. These common traits let you combine both development styles into unified projects. Features like “bridging headers” expose Objective-C classes to Swift, and vice versa. This confluence gives you the option to start adding Swift to your existing projects—without rebuilding entire libraries from scratch or refactoring your entire design.
Incremental adoption also enables you to start Swift development with flexible timelines and less overall pressure. Many developers are taking this cautious path.
Learn the Fundamentals
Whether you’re ready to use Swift in a project today or you’re thinking about future adoption, you should start learning Swift right away. Hop into Xcode, open a Swift playground, and begin to explore the language.
Start with Apple’s free eBook The Swift Programming Language, available on the iBooks store. Apple updates this book regularly as the language evolves, guaranteeing that the reference material is current for official releases. (However, the book doesn’t auto-update for Xcode betas.) An extensive “Revision History” section lets you explore documentation and language changes by date.
A second Apple eBook, Using Swift with Cocoa and Objective-C, is just as essential. It provides an overview of the topics related to interoperability between languages, and the details of API calls. It’s a much shorter volume due to its tight focus.
Make sure you’re regularly visiting Apple’s Swift Blog. The blog is updated only about once a month, but the coverage includes can’t-miss topics related to language features and case studies. Its mission statement speaks about behind-the-scenes peeks into language design, but the focus of the blog over time has been on more practical how-to articles.
The Apple Developer Forums provide the best access to Swift engineers. Navigate to Developer Tools > Language > Swift for a lively and up-to-date Swift language forum.
If you’re into IRC peer support, the Freenode (irc.freenode.net) #swift-lang room offers access to pro-level coding advice. It’s a language-specific room, so if you need help with Cocoa-specific APIs, visit #iphonedev or #macdev instead. A final room, #cocoa-init, is set up specifically to help mentor developers new to iOS and OS X.
Get Some Experience
Swift playgrounds are fantastic for learning Swift development;, you simply type a line or two of code and see immediate results. They’re perfect for working your way through the Swift Programming Language reference, enabling you to pick up language essentials.
From there, branch out to writing simple apps and testing hybrid solutions. I’ve found rewriting existing projects and libraries in Swift to be extremely valuable. The great thing about this approach is that you already know what you’re building. You don’t have to worry about algorithms or design; you’re just matching what’s already there with a new expressive paradigm.
This approach takes you further than tutorials can, making you bump up against language realities and limitations. Using older APIs, such as the C-based Quartz and Core Text routines, really pushes Swift knowledge and capabilities as you move away from objects and into direct memory access.
Real-world mastery isn’t just about language fundamentals. It’s about handling all the messy day-to-day details that pop up in any large project.
Wrap-Up
As you look toward the upcoming development year, consider how Swift will affect your apps. Make sure that you’ve researched Swift thoroughly, evaluating what it has to offer you as a developer both today and over the next few years. If you haven’t done so already, invest time in learning the language, and build some real code. There’s no better time than now to climb onto the Swift bandwagon so you’re ready for whatever the future holds.
Thanks, Jeremy Dowell, Gwynne Raskind, Landon Fuller.