Apple's new Swift programming language takes flight with Getty Images, American Airlines, LinkedIn, and Duolingo
Apple's new Swift programming language has only been available for a few months, but iOS and OS X developers from American Airlines, Getty Images, LinkedIn and Duolingo are reporting favorable impressions— ranging from increased productivity to fewer bugs in their shipping apps— as interest in the new language rapidly accelerates.
Swift, first introduced last June at Apple's Worldwide Developer Conference before shipping in September alongside iOS 8 and OS X Yosemite, tightly integrates with Chris Lattner's LLVM compiler. Swift intends to accelerate code writing, introduces modern programming concepts and aims to prevent common errors that can lead to app crashes.
Apple strategically invested in Swift
"We've been blown away by the reaction to Swift, our new programming language," Apple's chief executive Tim Cook stated last week. "Inventing a new programming language is something very few companies can do and we believe it will have a profound effect on our ecosystem."
"Inventing a new programming language is something very few companies can do and we believe it will have a profound effect on our ecosystem" - Tim Cook
Creating a new programming language is an ambitious undertaking, but rapidly gaining adoption among developers is also steep challenge. In addition to the unique ability Apple has to promote and encourage adoption of Swift as the owner of the iOS and OS X platforms, Swift is also— by design— intended to be easy to incorporate into existing development projects alongside existing Objective-C code.
A primary factor attracting developer interest in Swift is that— compared to Objective-C— it's easier for new programmers to adopt and quickly become productive. That comes in part from elements it borrows from existing languages including Rust, Haskell, Ruby, Python, C# and CLU.
Apple's free iBook on Swift calls the new language "the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language."
The company is also emphasizing the new language's performance, noting that Swift code implementing a common search algorithm can execute 2.6 times faster than Objective-C, or up to 8.4 times faster than comparable code written in Python.
Developers flock to Swift
Cook also stated, "Swift became available in September as part of the Xcode tools and in the first month those tools were downloaded over 11 million times. A recent report from RedMonk showed that Swift has had unprecedented growth and is quickly climbing the list of the most popular programming languages.
"We've seen many of our developers choosing Swift as they build significant new projects and we are seeing fantastic work with Swift going on in education. Very recently, Stanford University released their Developing iOS 8 Apps with Swift course, which was posted to iTunes University, making this amazing resource available to everyone in the world."
As reported by RedMonk in mid January, adoption of Apple's Swift has been "essentially unprecedented," entering the top 25 popular programming languages in just five months, a feat that Google's Go language took closer to five years to achieve.
A variety of international universities and technical schools are already incorporating Swift into their courses
Boosting Swift's popularity going forward is the fact that a variety of international universities and technical schools are already incorporating Swift into their courses, from Germany's Technical University of Munich to TecnolÃ³gico de Monterrey in Mexico, IngÃ©sup in France, Aberystwyth University and Plymouth University in Great Britain and RMIT University in Australia.
In addition to Stanford University in Apple's backyard, a series of other American campuses are also teaching Swift including California Polytechnic Institute, Cuesta College in San Luis Obispo, University of California at Santa Cruz, Drexel University in Philadelphia, Full Sail University near Orlando, Northwest Kansas Technical College, the University of Missouri and Southern Methodist University in Dallas.
Getty Images' Swift adoption within Stream
Raphael Miller, Manager of Application Development at Getty Images, told AppleInsider he first got started with Swift at WWDC, participating in a two day hackathon. That resulted in Stream, a new app for iOS and OS X that lets users search, browse and share professional photography from the Getty Images portfolio.
Miller noted that while senior developers experienced in Objective-C could quickly get started with Swift, the new language is particularly accessible to junior developers, who typically have a year or two of experience in C# or are fresh out of a university teaching Java. Web developers familiar with Ruby also seem quick to pick up Swift, in contrast to the less conventional syntax of Objective-C.
For these newer developers, Swift makes learning the default programming language of Apple's platforms easier, allowing them to focus on picking up and understanding the Mac Cocoa or iOS Cocoa Touch APIs, Miller stated.
While he described Swift as being "pretty performant" as a language, the primary advantages he noted related to developer productivity. In contrast to the verbosity of Objective-C, the terseness of Swift lets you "do more with a lot less code" and complete "mundane stuff quicker." That makes it particularly attractive to Ruby developers, he noted, resulting in "iess writing and more building." Ruby is commonly used to rapidly prototype new concepts.
Swift's edge in developer productivity is particularly important in the consumer space, Miller noted, where developers seek to keep their apps fresh with new features and other tangible enhancements. With Swift, developers can "knock stuff out quickly," enabling innovative iteration while rapidly responding to user requests for new capabilities.
Swift also won't let you compile code with common errors, which "lets you know early on when you're doing something wrong," Miller said. Developers are "notified while you're typing code why this isn't going to work," sparing them the time wasted in compiling code with flaws.
Miller noted that while the initial Swift betas were "pretty raw," since then "each release has gotten better." While there are "still some crashes in Xcode" related to compiler issues and some problems with intermixing Objective-C and Swift, Miller said that the success of Stream— which is written entirely in Swift— has his team "ready to start the conversion of all our apps to Swift," with the full Getty Images app targeting a near term goal of reaching 50 to 60 percent Swift code.
Getty Images isn't doing any Android app development and Miller said it has no cross platform plans in the near future, so investing in Swift isn't constrained by portability issues. However, he also noted that Swift workshops run by his mobile team are gaining the attention of other developers in the company, including backend API coders using Microsoft's C# and web developers familiar with Ruby.
Swift has "people banging on our door," Miller said, particularly given the interest in mobile development in general. And unlike the less approachable syntax of Objective-C, the familiarity of Swift means that existing developers with an interest in expanding their skill set into mobile apps are "syntactically not scared of it."
Asked what he'd like to see from Apple related to Swift in the future, Miller said, "it would be nice to see more sample code" demonstrating, "here's a common problem, here's how you'd do it in Swift vs Objective-C," and outlining a cost benefit analysis of using Swift for different tasks
"Objective-C has been around so long, the best practices are out there," Miller stated. For Swift, there's less best practice architecture available, and ideally the best insight on how to use Swift most effectively would come from "from guys who designed it."
Swift takes off at American Airlines
AppleInsider also spoke with Phillip Easter, who manages American Airlines mobile app, and the company's iOS developer Matt Klosterman. Easter noted that American seeks to remain "progressive in the mobile space, looking for ways to improve our development cycle and for improvements to the platform," adding, "what Apple is doing with Swift is a great addition."
He noted Swift's tangible benefits include higher quality code that's easier to maintain along with related performance enhancements, and said American is "definitely adopting Swift going forward."
However, as a native shop with a large existing code base, simply porting code from Objective-C to Swift is less attractive than being able to to build new features and enhancements in Swift. Apple has made it relatively easy to take such an incremental approach toward adopting Swift into existing projects.
Klosterman said he began investigating Swift immediately after WWDC, developing an "opportunistic approach to use it for new features" in the company's existing app. However, adopting Swift as a way to rapidly add new features isn't the only platform-related shift that developers at American needed to consider in the rollout of iOS 8.
iOS 8 also introduced support for Adaptive User Interfaces, which allow developers to flexibly adapt their apps to work on new device form factors— which Apple delivered just in time for the larger screens and higher resolutions of iPhone 6 and iPhone 6 Plus.
That feature enabled American Airlines to merge its separate iPhone and iPad apps to a common code base, making it easier to keep both apps in feature parity while significantly enhancing the ability to create and add new features. Adopting Swift to develop those new features dovetailed with support for Adaptive UI, accelerating development but also introducing new ways to think about how existing Objective-C code could be integrated with new Swift code.
Like Getty Images, American Airlines is also following an "incremental approach" in its adoption of Swift. Klosterman similarly noted iterative improvements to Swift since its debut at WWDC, noting that it "evolves with every release."
Asked what he'd like to see happen in the future, he noted that because Objective-C and Swift will "both be around for a while, it would be beneficial if interoperability improved with Swift," after noting that there are "interesting ways" that interoperability between the two could evolve.
At the same time, despite Swift appearing to be a freshly minted new language, Easter described it as having a "history and pedigree," having been in development for four years. "Apple has proven very thoughtful in what its doing," he stated.
LinkedIn adopts Swift for SlideShare
Apple's introduction of Swift last summer coincided with the conceptual prototyping of the new SlideShare app by LinkedIn, which hosts shared business presentations, infographics and videos similar to an Instagram for sharing presentations between business professionals.
SlideShare's Engineering Manager Francisco Meza stated that the "timing worked perfectly for us to develop a brand new application completely in Swift (except for the little pieces of Objective-C required for interoperability), as we were just finishing the first early prototype of what would become the SlideShare iOS app."
Product Manager Andri Kristinsson added that the SlideShare team "was very excited to work with a brand new language right after it got announced ad WWDC and learn the ropes as we progressed building our app. We felt like we were working closely with the entire developer community during the team, our developers were active on forums and stack overflow-both learning and helping others learn," noting that "there were a couple of minor improvements we reported to Apple and those were added very shortly."
When asked about Swift's performance, Meza answered, "I must say that I am very satisfied by runtime performance of Swift based on the comparison of performance tracking metrics for similar pages of both SlideShare's app (Swift) and LinkedIn's flagship app (Objective-C)."
In terms of resulting code quality and stability, Kristinsson noted that "the crash rate of the SlideShare app is excellent and much better than in other apps our team has developed before."
Meza also addressed Swift's learning curve, stating that it "was not too steep. Swift is indeed a new language but it takes inspiration and borrows elements from other programing languages that have been around for a very long time: Ruby and Python among them. The high level of expertise in Ruby of the developers working on this project helped to flatten the learning curve of the adoption of Swift."
He added, "Given the great experience we have had with Swift so far, SlideShare will continue using it as its language of choice for iOS development."
Meza noted some issues experienced early on, including the lack of a private access modifier in the first few patch releases and initial issues with Xcode syntax highlighting, both of which he said have since been resolved.
"With the language itself," he added, "I believe the main issue we experienced was the fact that the language idioms were not yet established when we started using it, so part of our process of learning to work with Swift was coming up with our own conventions for best practices in the use of the language."
Meza added, "my main missing feature is support for exceptions, as in our experience, the writing of error handling could code could benefit with the use of this feature."
However, weighed against, as he described, "the benefits provided by using Swift— code that is more expressive, code that is easier to read and understand and code that is easier to maintain— I can confidently say that that decision of going with Swift instead of Objective-C was the right one for us."
Duolingo learns a new language
Another example of a new development project using Swift is Duolingo's Test Center, a companion app to the company's popular Duolingo foreign language learning app. Test Center is intended to certify a user's language proficiency in a monitored, time-limited exam.
A blog posting by the company titled "Real World Swift" described the original goals for Test Center, noting that it is "not a very performance-sensitive app," but that it was critical for it to be stable, as crashes would not only provide a "pretty bad user experience" for such an exam app, but also disrupt its design as a time-limited skill test.
Duolingo outlined detailed experiences with specific Swift features, but concluded that its Test Center app— developed "a bit over three months" by a single programmer— was able to achieve the intended goal of a "low number of crashes" in the hands of users as a popular download. Moreover, of the crashes the company tracked, four of the top five crash report triggers were related to code in an external Objective-C library, rather than its brand new Swift code.
The company attributed its app's stability in large part to "a solid software architecture and our adherence to sound engineering principles," but noted that "Swift eased the process of building this architecture and following best practices by eliminating entire classes of bugs by design. Correctly using Swift's type system, for example, caught and prevented numerous type errors at compile time during development, rather than ever surfacing in production."
Duolingo also identified some early adopter problems with Swift, noting "this newly minted language lacks some of the expressiveness found in other languages with modern type systems." The company also noted that its "biggest gripe-and source of frustration-with Swift is probably not the language itself, but the tooling around it."
It stated that "Xcode (Apple's Objective-C and Swift IDE) does not yet feel solid with Swift code. During development of our app, the IDE would often slow down noticeably or crash. There was no (or very slow) code completion most of the time, basically no debugger, unstable and unreliable syntax highlighting, a slow text editor (once the project reached a certain size), and no refactoring tools. Additionally, compiler errors are often incomprehensible and there are still quite a few compiler bugs and missing features (e.g. type inference sometimes goes awry)."
The company added, "while Xcode has gotten significantly better since we started, most of those points still hold true today, and somewhat spoil the experience. We're hoping that Apple shifts some of its focus to improving the developer tools."
The developers concluded, based on their initial experience with Test Center, that "Swift can be used to write stable, robust, and high-volume production apps. Our main app, Duolingo, already uses some Swift code, and we're planning on using it more and more in the future."
The company also recommended, "if you already have an app in Objective-C, you probably don't want to rewrite it from scratch just for the sake of using Swift, but you could consider adding new components in Swift."
As an example, the company described an app component that renders PDF assets, written in Swift. It was possible to use this Swift component in existing Objective-C code using a wrapper method. Conversely, the company stated that "it was easy to lift some of the existing Objective-C components of our main app and use them from Swift."
Swift plays a strategic role in Apple Watch, IBM iPad apps
Apple's pragmatic approach to making Swift interoperable with Objective-C appears to be working to enable iOS and Mac developers to incrementally adopt the new language, getting their feet wet without having to start over from scratch. Apple is also making extensive use of Swift itself, and is supporting new development in Swift for the upcoming Apple Watch.
Swift is also credited with playing a significant role in Apple's recent partnership with IBM to develop a new class of "Mobile Ready" iPad apps for mobile business users. Last Summer, Cook stated, "we've forged a relationship with IBM to deliver a new class of mobile business solutions to enterprise customers around the world. We're working together to provide companies access to the power of big data analytics right on every employee's iPhone or iPad.
"Using Swift, we will collaborate to bring over 100 MobileFirst apps to enterprise clients, each addressing a specific industry need or opportunity. This is a radical step for enterprise. It opens a large market opportunity for Apple."