Feeds

Apple: We'll tailor Swift to be a fast new programming language

Kiss goodbye to five years of Objective-C

Intelligent flash storage arrays

WWDC Apple stunned the audience at its Worldwide Developers Conference in San Francisco on Monday with a tool few expected: a new programming language for iOS and OS X software called Swift.

There already is a programming language called Swift that was developed by the University of Chicago and Argonne National Laboratory for use in parallel computing applications. This isn't that.

What it is, is an entirely new syntax that – in the words of Apple senior VP Craig Federighi, who unveiled it during the Monday morning WWDC keynote – aims to be "Objective-C without the baggage of C."

Some of that "baggage" will already be familiar to developers who cut their teeth on C but later moved on to scripting languages such as Python (and Federighi compared Swift to Python several times during his presentation).

Like scripting languages but unlike C, Swift lets you get straight to the point. The single line println("Hello, world") is a complete program in Swift. Note, also, that you don't even have to end the statement with a semicolon, as you do in C. Those are optional, unless you're combining multiple statements on a single line.

Swift also aims for a level of scripting language–like interactivity. At WWDC, Apple developer-tools chief Chris Lattner demoed coding using a feature called "playgrounds," which allow a developer to modify portions of a program in Xcode and see the results in an output window in real time.

Craig Federighi introducing Swift at WWDC

Swift code outperforms Python by a wide margin, Federighi said, and even beats Objective-C

Unlike scripting languages, however, Swift is compiled, using a compiler based on the LLVM project (which Lattner created before joining Apple in 2005). That means programs written in it are fast. Compared to Python, Federighi said, a complex object sort written in Swift ran 3.9 times faster, and RC4 encryption ran 220 times faster. In fact, he said, the Swift code even ran faster than the same algorithms implemented in Objective-C.

Familiar, yet new

Swift is object-oriented, but it also supports some functional programming styles. Functions can be passed around as data, for example, and the language also supports closures.

It also adopts a number of modern language features, such as optional typing, generics, type inference, namespaces, and tuples as a data type. Identifiers can be composed of any Unicode characters – so you can name your variables in Chinese, for example, or even use symbols.

Swift has also been designed to make it easier for developers to write secure code. Federighi said the language's syntax "defines away large classes of common programming errors; they're just not possible."

According to Apple's developer documentation, Cupertino spent years developing Swift as a 21st-century language that's suitable for everything from short programs to entire operating systems.

"Swift combines the best in modern language thinking with wisdom from the wider Apple engineering culture," the manual not-so-humbly states. "The compiler is optimized for performance, and the language is optimized for development, without compromising on either."

At the same time, Swift is designed to be fully interoperable with Objective-C. Objective-C APIs can be called from within Swift code and vice versa. Code written in both languages can be mixed and matched within the same program, and migrating code from one language to the other should be easy.

That in turn means Swift already supports Apple's key development frameworks, including Cocoa and Cocoa Touch.

What you shouldn't expect from Swift, however, is a general-purpose programming language for use outside Apple's ecosystem. The fruity firm made no mention on Monday of how it plans to license Swift, whether it will release the source code to its compiler, or whether it will be possible to write code in Swift for platforms other than iOS and OS X – but we think maybe you shouldn't hold your breath for any of that.

In addition to its online documentation, Apple has released an e-book, The Swift Programming Language, that's a free download from the iBooks Store.

To start working with the language itself, you'll need to download the beta release of XCode 6, which includes tutorials to get you going. ®

Remote control for virtualized desktops

More from The Register

next story
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
NSA SOURCE CODE LEAK: Information slurp tools to appear online
Now you can run your own intelligence agency
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
First in line to order a Nexus 6? AT&T has a BRICK for you
Black Screen of Death plagues early Google-mobe batch
Whistling Google: PLEASE! Brussels can only hurt Europe, not us
And Commish is VERY pro-Google. Why should we worry?
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Getting started with customer-focused identity management
Learn why identity is a fundamental requirement to digital growth, and how without it there is no way to identify and engage customers in a meaningful way.
Go beyond APM with real-time IT operations analytics
How IT operations teams can harness the wealth of wire data already flowing through their environment for real-time operational intelligence.
Why CIOs should rethink endpoint data protection in the age of mobility
Assessing trends in data protection, specifically with respect to mobile devices, BYOD, and remote employees.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?