Feeds

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

Kiss goodbye to five years of Objective-C

Securing Web Applications Made Simple and Scalable

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

Bridging the IT gap between rising business demands and ageing tools

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
Mozilla fixes CRITICAL security holes in Firefox, urges v31 upgrade
Misc memory hazards 'could be exploited' - and guess what, one's a Javascript vuln
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
Seven Steps to Software Security
Seven practical steps you can begin to take today to secure your applications and prevent the damages a successful cyber-attack can cause.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.