Apple Releases Swift, a High-performance High-level Language for iOS and OSX

| by Alex Blewitt on Jun 03, 2014. Estimated reading time: 2 minutes |

Today at WWDC 2014, Apple announced the beta availability of a new programming language, Swift, which is set to ship with iOS 8 and OSX Yosemite later this year. Swift is a high-level programming language that will be familiar to JavaScript developers, but is compiled using LLVM to produce highly performant executable code for both OSX and iOS platforms.

Apple has heavily invested in LLVM technologies, which provide an abstract instruction set that can be translated for specific architectures. Clang replaced GCC as the compiler of choice for C and Objective-C programs, and both of those are translated with Clang into LLVM instructions, which are then optimised into an executable for the platform. The new programming language, Swift, produces LLVM bytecode in the same way and can co-exist with existing Objective-C applications and libraries.

In addition, swift also comes with a REPL environment for testing code. Normally used by interpreted languages such as JavaScript or Python, a REPL provides a Read-Evaluate-Print Loop that can be used to evaluate individual expressions and statements at the command line for easy debugging. Combined with powerful looping, string interpolation and printing/debugging options, it allows an interactive style of development and testing that is frequently missing for compiled languages such as C and Java.

Swift is a strongly typed language, though it uses type inference to reduce the amount of characters typed by the developer. Types can be provided explicitly, and for numeric types, specific sized elements such as UInt8 or Int32 can be used.The type engine also provides for Optional valued types; an optional value can be dereferenced with a ? or ! depending on whether the value is expected to exist. The collections in Swift provide literal support for both arrays (with []) and dictionaries/maps (with [:]) and can include generic types.

Functions are also first class elements in the language, and can be used to pass functions as variables to other elements. Arguments can also be named explicitly (which provides compatibility with Objective-C’s named arguments) or provided as positional arguments only. Parameters can also have default values, allowing arguments to be omitted if not required.

The swift integration can use Objective-C objects, both from the standard libraries (such as UIKit or Cocoa) as well as user-defined types. Classes can also be created in swift natively (which can then also be used from Objective-C) which, like other Objective-C objects, are reference counted. (The references are managed automatically by the runtime, so the user does not need to worry about memory management in swift directly.) As well as classes, which are reference types, it is possible to create struct value types that can be passed by copy as values to function types.

Finally swift has multiple return types, through the use of tuples. These tuples can be used in matching semantics (with the case statement) or variable assignment.

Swift is available via the Xcode 6 developer preview, and will be released in production in the next few months. At this time, there is no confirmation that the swift language will be merged upstream with LLVM, but having recently merged the ARM 64-bit support and worked on the fast JIT for Safari’s JavaScript, it is likely that some of it will fold into the upstream clang runtime hosted by LLVM. This could provide the ability for swift programs to be written for other architectures where there is a clang compiler.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Nice functional-first languge by Faisal Waris

Nice language functional-first language with a REPL, pattern matching, algebraic data types, etc. BTW Joe Palmer (ex F# guy) is working on Swift.

Re: Nice functional-first languge by Anurag Joshi

Where do you see algebraic data types? Also I wouldn't call it functional first. It's an OO language with support for first class functions.

Re: Nice functional-first languge by Faisal Waris

Its called enums but you have to read the Swift enum page to the end to see the ADT info:

Also read the post on Swift by the designer of the Rust language:

Swift has type inference, first-class functions, closures , pattern matching, ADTs, tuples / destructuring assignments, structs, etc. and hence most closely resembles other functional-first languages like OCaml, F# and Rust.

Ruby as an alternative by Michel Löhr

Ruby which has most of this features is already available via rubymotion (.com), compiles also in LLVM and provides REPL. I am curious to see what Swift provides for meta programming features as ruby does.

NB the next release of rubymotion will support Andriod as well which makes it possible to use the same language without bridging but with native bytecode support for iOS or Java.

Re: Nice functional-first languge by Anurag Joshi

Thanks good to know.

Re: Ruby as an alternative by Tim Williams

No thanks. I want types, type-checking and an efficient runtime.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

6 Discuss