CONTACT

iOS 8 in context: Swift is the language of Apple’s future

Connor Mason
  • Connor Mason
  • September 30, 2014
iOS 8 in context: Swift is the language of Apple’s future

In previous years, Apple’s keynote at its annual Worldwide Developers Conference has been the platform for the introduction of consumer-facing products and features, including the iPhone 4 in 2010 and iOS 7 in 2013. But this year’s conference was different—the final third of Apple’s presentation addressed almost zero consumer features. Instead, Cook and his team fulfilled thousands of developers’ wish lists to the sound of thunderous applause. While non-developers might have been itching for a glimpse of this fall’s anticipated new iPhones, little did they know that these additions to iOS will have a greater impact on their everyday lives than any flashy new hardware or buzz-worthy new feature.

If the redesign in iOS 7 was a fresh paint job, iOS 8 will be an entirely new engine. This is iOS 8 in context.

Swift

The story of Swift begins with Steve Jobs‘s second company, NeXT.

In 1983, Brad Cox and Tom Love introduced a modified version of the longstanding C programming language called Objective-C. The new language incorporated object-oriented programming, which handles conceptual “objects” that can have various attributes, and was designed to coexist with legacy C code. When Steve Jobs founded NeXT during his exile from Apple, the company designed its forward-thinking NeXTSTEP operating system to run apps built in Objective-C, which ignited developer interest in the language as they explored the exciting new platform. NeXT developed new libraries in Objective-C to power apps on their computers, and introduced a programming environment called Project Builder to facilitate Objective-C NeXTSTEP app construction.

When Apple acquired NeXT in 1996, this commitment to Objective-C programming infected the Mac OS platform, as well. As NeXTSTEP was transformed to replace the legacy Mac operating system with what would be known as Mac OS X, Objective-C became the foundation for Apple’s revolutionary new direction. The Project Builder developer tool became Xcode, and a new generation of Mac developers were exposed to Objective-C as they prepared apps for Steve Jobs’s Mac OS X. Over the years, Apple invested heavily in their operating system with Objective-C, introducing a number of APIs and frameworks built in the language. When the company announced the iPhone in 2007, its fledgling operating system—then called iPhone OS—was an evolution of OS X with the same Objective-C capabilities.

“I love Objective-C,” said Punchkick iOS developer Chris Cieslak. “I wrote Objective-C back before the iPhone, when it was Mac-only, as a hobbyist. It was a great alternative to C++, but there wasn’t a market back then for Mac developers like there is today. So I was overjoyed when the iPhone SDK came out, because it presented new opportunities for Mac developers.”

Because of the massive growth in popularity for iOS products, Objective-C has enjoyed widespread adoption and use among the developer community in the last few years. Any of the millions of iPhone and iPad apps populating the App Store is built in Objective-C, and each has a team of hardworking developers who code in the language all day. But it has never been perfect—a programming language designed in 1983 couldn’t possibly account for modern challenges, no matter how many helpful developer tools are built on top of it. That’s why developers were so thrilled when Apple surprised them with the news that it had developed an entirely new programming language, billed as “Objective-C without the C.” It’s called Swift, and it’s going to change the way millions of developers approach iOS and OS X.

Apple has a whole new objective, C?

A lot has changed in the 31 years since Objective-C was first designed, and Swift is a play to bring OS X and iOS up to date and into the future. Although Apple has added substantial new changes to Objective-C over the years, like blocks and synthesized properties, there were only so many updates it could before beginning to move on completely. Apple created Swift with an awareness of modern programming languages, offering clean, easy-to-read syntax and simplified organization features to eliminate the need for .h header files.

“I’ve begun dabbling in Swift a little bit by going through Apple’s tutorials,” said Punchkick iOS developer J.C. Subida. “The syntax is beautiful, greatly simplified. If you can read and understand the code much easier, you can create and change it much easier.”

Apple designed Swift to coexist peacefully with existing C or Objective-C code. Swift shares the same runtime with these older languages, so both can run in tandem—even within the same app. This means that developers with an existing Objective-C codebase can begin using Swift in their iOS 8 or OS X 10.10 applications right away, easing the transition between languages.

More important than elegance is ease of use—Swift is designed to make many longstanding Objective-C programming hangups nightmares of the past. Swift checks developers’ work on the fly, initializing variables before use and checking arrays and integers for overflow. “I’ve played with the new language a lot,” said Chris Cieslak. “I think Swift is a great step forward in removing a lot of the typical pain points associated with writing iOS apps.” Some of the changes seem minor, but will have a massive impact on developers’ workflows.

“One of the biggest problems in Objective-C was that it’s possible to accidentally reference an object in memory that’s no longer there,” said Cieslak. “It would just crash your app. When developers are writing their code, they have to consider if a value could be ‘null,’ and you have to specifically unwrap variables. With Swift, it’s difficult to make that mistake because all variables are initialized with a value, unless they’re of the ‘optional’ type. Swift provides language constructs that force you to think about these things as you’re writing the line of code.”

Another example is the inclusion of automatic reference counting in Swift versus a tedious developer process in Objective-C. In OS X 10.5 Leopard and iOS 4, Apple introduced automatic reference counting, or ARC, to help developers keep track of complex “retain” and “release” calls throughout their code. The addition made programming in iOS and OS X easier, but Swift takes ARC even further.

“In Objective-C, developers had to manually write and keep track of these ‘retain’ and ‘release’ calls in their heads. Now, ARC puts them into the program when you compile as if you wrote them,” said Cieslak. “ARC was grafted into Objective-C a few years ago, but Swift has ARC baked in from the get-go.”

Because of Apple’s extensive experience writing for their own platforms, its developers intimately understand the more frustrating issues they’d run into. “Objective-C is a double-edged sword,” said Cieslak. “It’s powerful, but really easy to make mistakes. Some tasks, like memory management, have to be done manually, unlike languages like Java, which feature automatic garbage collection. Developers have to be cognizant of times when the system isn’t managing memory.” With Swift, Cieslak says, these problems are accounted for.

“Swift makes it much harder to make common mistakes. That in and of itself is a huge improvement over Objective-C.”

Native speakers know the idioms

The biggest obstacle facing any new language, spoken or coded, is attaining fluent speakers. With their new language, Apple emphasized easy learnability to ensure a low barrier to entry and encourage swift adoption. The syntax was designed with legibility in mind, similar to human-friendly languages Python and Ruby, to help newcomers and veterans alike better understand how existing codebases operate with as shallow a learning curve as possible.

“I first learned Ruby, so I’m used to more user-friendly languages,” said Punchkick developer John Norton. “Apple wants to make programming more accessible to people with Swift, and they’re changing the paradigm with things like Xcode Playgrounds. They could change the way people think about programming.”

Unknown

The new version of Xcode was specifically designed to aid developers as they began exploring Swift’s capabilities. Built-in tools called Playgrounds allow developers to view their code’s impact in real time, so they can better understand their creations as they physically type. A new overlay shows a live preview of an app view that transforms in real time as new lines of code are added, introducing a degree of interactivity and play to the Swift programming experience.

“Swift will definitely break down the barriers to learning how to code,” said J.C. Subida. “It was designed to facilitate adoption among developers new to iOS. The whole idea of Xcode’s Playgrounds integrates something like a tutorial into the code—it’s intended only to help with learning.”

“A lot of senior developers have said that Swift is similar to Scala,” continued Norton, “which puts it closer to Python and Ruby in terms of readability. It’s not as explicit or verbose as Objective-C, but the readability means that more people are going to feel comfortable using the language.” This instant accessibility, combined with Apple’s uniquely broad and engaged developer audience, could drive Swift adoption among newcomers and longstanding iOS developers alike.

Heavy Swifting

But the switch to Swift won’t happen overnight. “Because it’s a complete overhaul of the language,” said Punchkick iOS engineer Sean Samocki, “I think it’ll be a while before we see apps completely rewritten in Swift. Especially because so many iOS apps out there have such a huge codebase, they can’t be rewritten overnight.” One factor aiding a gradual adoption is Swift’s ability to coexist with C and Objective-C within the same app, but writing new Swift apps from scratch are the next logical step of iOS developers.

Just as Apple phased out the floppy disk and iteratively eliminated CD and DVD drives from modern Macs, developers anticipate that Apple might have similar plans for the longstanding Objective-C language. “It’ll be interesting to see the ratio of Objective-C and Swift usage for new apps over the next few years,” said Samocki. “I’m really curious what the adoption rate will be—especially considering that Apple seems to be implying that it’ll phase out Objective-C eventually.”

With marketing phrases praising Swift as the “future of Objective-C,” Apple seems to be implying that it’ll phase Objective-C out.

Because the Swift programming language will not be cross-compatible with non-Apple platforms like Android and Windows Phone, software engineers who specialize in Swift will be locked into iOS development. (The same goes for iOS applications written in Swift, but apps written for iOS and Android today won’t be cross-compatible, either.) In future versions of OS X and iOS, Apple might invest in Swift-specific versions of Cocoa and Cocoa Touch, collections of frameworks like Core Animation and UIKit that allow apps to leverage the operating systems’ various capabilities. In addition, future frameworks for theoretical capabilities might only be added to the Swift-oriented frameworks, meaning developers would need to reform their apps in Swift to take advantage of exciting new features. This could lock out third-party applications dependent on today’s frameworks, which are all built on Objective-C.

A sampling of some of the interface tools UIKit provides to developers. Source: Bryan Clark

A sampling of some of the interface tools UIKit provides to developers. Source: Bryan Clark

But Swift could have the larger impact of allowing developers to release better applications on iOS than those available on Android with no additional work. With Swift’s failsafes to prevent common programming oversights, applications for iOS written in Swift can be on average more stable, more reliable, and offer a better overall customer experience. “I think in the short term, Swift is going to be a good learning experience for a lot of developers out there,” said Samocki, “but once developers jump on the Swift bandwagon, we’ll be able to make apps more efficiently and with fewer bugs.”

Beyond reliability, Swift could usher in a new generation of apps written uniquely for the unique language. “If you’re writing an app in Swift, you might not approach it the same way you would in Objective-C,” said John Norton. “Every programming language gives you different expressiveness or ways of doing things, which can lead to different apps.”

“There are things that people may intuitively think to do that they may not have before, just because of the different structure of a new language and the way the new language interacts with the developer. You’re still building the same apps, but because the language is different, the end product might be different.”

The matter of iOS app development has more pressing implications for consumers than the complex subject matter might imply. The adoption and evolution of Swift could have a serious impact on the story of iOS’s future, and could inspire new ideas among the thousands of iOS developers who start learning it and deploying it. Now that Apple has a programming language and two computing platforms it completely controls, the company can begin iterating with new features and unprecedented capabilities with greater acceleration. Years from now, when Apple introduces new whiz-bang features that delight its customers on future iPhones, iPads, and Macs, many of those capabilities will be built on the foundation set by Swift. And the new crop of iOS programmers who get their start on Swift might grow to become the next generation of Zuckerbergs and Wozniaks.

Connect

Let’s Build Together

Thanks for reaching out!

We will be in touch shortly.