Affiliate Disclosure
If you buy through our links, we may get a commission. Read our ethics policy.

Apple's top secret Swift language grew from work to sustain Objective C, which it now aims to replace

Work on Swift— Apple's surprise new programming language unveiled at WWDC— started development four years ago in conjunction with efforts to keep Objective C relevant. Swift now aims to quickly replace Objective C for modern Cocoa development on iOS and OS X.

Rather than being an entirely new "beta" idea, work on Swift started in the summer of 2010, according to the new language's originator Chris Lattner (below), who has worked at Apple since 2005. Lattner is probably best known for LLVM, the Low Level Virtual Machine compiler infrastructure project with a wyvern dragon mascot (above).

LLVM: A new compiler for Objective C

LLVM originated as Lattner's research project while a student at the University of Illinois, Urbana-Champaign in 2000. It was first publicly released as version 1.0 in 2003. In 2004, Lattner was a summer intern at Microsoft Research, where he worked on the Phoenix complier infrastructure, working to allow LLVM to compile and run .NET code.

Chris Lattner

Lattner caught the attention of Apple after posting questions about Objective-C to the company's objc-language mailing list. Apple in turn began contributing to Lattner's LLVM open source project in 2005 and subsequently hired Lattner and began funding his work.

In 2007, the LLVM project released Clang, a front end code parser for Objective C/C/C++ aimed to provide fast compiling with low memory use, expressive diagnostics, a modular library-based architecture, and tight integration within an IDE such as Apple's Xcode.

In addition to the "pure" LLVM Clang project, Lattner also proposed integrating the new LLVM, featuring its advanced code optimizer and code generator, into the existing GCC (GNU C Compiler), adding modern methods for "aggressive loop, standard scalar, and interprocedural optimizations and interprocedural analyses" missing in the standard GCC components that had long been a core element of the development tools in Unix operating systems like Apple's OS X.

GCC's support for Objective C, the primary development language of Apple's OS X Cocoa (and NeXTStep, its historical predecessor), had grown stagnant, so Apple's motivation for funding the open development of both Clang and LLVM-GCC involved keeping the Mac's Objective C relevant as a language.

Apple began aggressively using LLVM in OS X, providing LLVM-GCC to its Mac developers in order to provide access to the new LLVM compiler and benefit from its code optimizations without requiring substantial changes to their workflow based on the previous GCC.

The company also integrated LLVM into the OpenGL stack of OS X 10.5 Leopard in 2006, and leveraged LLVM to help in migrating the Mac to Intel beginning in 2005 and to the ARM architecture for the iPhone in 2007.

By the 2012 release of OS X Mountain Lion and iOS 6, Apple had moved entirely to Clang, leaving both LLVM-GCC and GCC behind. LLVM not only powers Apple's software, but is also tightly integrated into the development of Apple's custom silicon, including the A6 and A7 Application Processors.

LLVM also plays a key role in other Apple technologies, from the LLDB debugger to new APIs including Metal, Apple's new layer for high performance graphics on iOS that exposes the graphics capabilities of the newest A7 with the least possible overhead, delivering a significant performance boost over using the more general purpose OpenGL.

Swift: A new language for LLVM

By 2010, LLVM's solution to GCC's stagnant Objective C support created a new scenario where LLVM could now support more features than could be easily added to Objective C. Lattner began working on a new programming language that summer, and a year later was joined by "a few other (amazing) people."

By July 2013, Lattner noted that the new Swift project had become "major focus for the Apple Developer Tools group." It remained a secret to the public for the next year. Lattner notes in his resume that he "took over management and leadership of the entire Developer Tools department at Apple" at the beginning of 2013.

"In addition to compilers and low-level tools," Lattner notes, "I am now responsible for the Xcode IDE, Instruments performance analysis tool, Apple Java releases, and a variety of internal tools. Xcode 5 is the first result of this work, though much of the feature planning and implementation was complete before I took over. I drove convergence and defined a few key features that were released at WWDC."

Lattner noted that the new Swift language "is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list."

Apple's free iBook on Swift also notes that "Swift has been years in the making," adding that "Apple laid the foundation for Swift by advancing our existing compiler, debugger, and framework infrastructure.

"We simplified memory management with Automatic Reference Counting (ARC). Our framework stack, built on the solid base of Foundation and Cocoa, has been modernized and standardized throughout. Objective-C itself has evolved to support blocks, collection literals, and modules, enabling framework adoption of modern language technologies without disruption. Thanks to this groundwork, we can now introduce a new language for the future of Apple software development.""Swift is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language"

The company also observes that Swift "is friendly to new programmers. It is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language."

Apple also draws attention to the integration between Swift and LLVM, noting that the new language "combines the best in modern language thinking with wisdom from the wider Apple engineering culture. The compiler is optimized for performance, and the language is optimized for development, without compromising on either."

Swift's Interactive Playgrounds & REPL

Lattner also commented on two new features associated with Swift: Xcode's new Playgrounds (below) and REPL (Read-Eval-Print-Loop) debugging console.

"The Xcode Playgrounds feature and REPL were a personal passion of mine, to make programming more interactive and approachable," Lattner noted. "The Xcode and LLDB teams have done a phenomenal job turning crazy ideas into something truly great.

"Playgrounds were heavily influenced by Bret Victor's ideas [which are cited as a inspiration for Khan Academy's online environment for learning to program], by Light Table [an open source IDE designed to provide realtime feedback about code and how programs work] and by many other interactive systems.

"I hope that by making programming more approachable and fun, we'll appeal to the next generation of programmers and to help redefine how Computer Science is taught," Lattner stated.

Apple's presentation of Swift notes that "Playgrounds make writing Swift code incredibly simple and fun. Type a line of code and the result appears immediately. If your code runs over time, for instance through a loop, you can watch its progress in the timeline assistant. The timeline displays variables in a graph, draws each step when composing a view, and can play an animated SpriteKit scene. When you've perfected your code in the playground, simply move that code into your project."

The company states that Xcode's Playground lets users "design a new algorithm, watching its results every step of the way; create new tests, verifying they work before promoting into your test suite; experiment with new APIs to hone your Swift coding skills."

Apple notes that the REPL debugging console in Xcode "includes an interactive version of the Swift language built right in. Use Swift syntax to evaluate and interact with your running app, or write new code to see how it works in a script-like environment."

Apple says it plans to rapidly evolve Swift in response to developers needs and feature requests.

Thinkful, an education startup focused on mentor-led programming education, has already announced plans to offer a course on developing in Swift, in a program that begins July 16.