Feeds

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

Kiss goodbye to five years of Objective-C

Choosing a cloud hosting partner with confidence

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. ®

Intelligent flash storage arrays

More from The Register

next story
Netscape Navigator - the browser that started it all - turns 20
It was 20 years ago today, Marc Andreeesen taught the band to play
Sway: Microsoft's new Office app doesn't have an Undo function
Content aggregation, meet the workplace ... oh
Sign off my IT project or I’ll PHONE your MUM
Honestly, it’s a piece of piss
Return of the Jedi – Apache reclaims web server crown
.london, .hamburg and .公司 - that's .com in Chinese - storm the web server charts
NetWare sales revive in China thanks to that man Snowden
If it ain't Microsoft, it's in fashion behind the Great Firewall
Chrome 38's new HTML tag support makes fatties FIT and SKINNIER
First browser to protect networks' bandwith using official spec
Admins! Never mind POODLE, there're NEW OpenSSL bugs to splat
Four new patches for open-source crypto libraries
prev story

Whitepapers

Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Cloud and hybrid-cloud data protection for VMware
Learn how quick and easy it is to configure backups and perform restores for VMware environments.
Three 1TB solid state scorchers up for grabs
Big SSDs can be expensive but think big and think free because you could be the lucky winner of one of three 1TB Samsung SSD 840 EVO drives that we’re giving away worth over £300 apiece.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.