Why non-Apple developers should care about Swift

Now open source with Linux support, Swift has a great deal to offer cross-platform and server-side developers

Last week Apple delivered on a promise: Its Swift language is now open source. Unveiled a little more than a year ago, Swift is part of the C family, designed with an eye toward general-purpose application development. The initial Apple releases of Swift focused on the development of new desktop and mobile apps, using the LLVM compiler. The result is a new language that takes advantage of much current thinking in language design, mixing the complexity and depth of C with the ease of use of interpreted languages like Python. It’s also fast, designed to work well with large arrays and collections.

The open source release of Swift continues the language’s development, adding both Linux support and server-side language features. Swift was already on a fast track: In the year or so it has been available, Swift has jumped to version 2.2, adding language-specific features to the LLVM and clang compilers. There is no Windows version of Swift yet, though Microsoft has added Swift support for iOS and OS X applications in its latest Visual Studio releases.

If you’re working with Swift on OS X, Swift in Xcode is very much the same, familiar development environment that Objective-C developers have used for years, with the two languages drawing on the same compiler. Apple has described Swift as “Objective-C without the C.”

That’s because Swift is really an abstraction of Objective-C and the underlying LLVM compiler. In fact, Swift is so closely related to Objective-C, you could almost describe Swift as a new dialect of Objective-C that simplifies certain key constructs and makes code more readable. Swift builds upon Objective-C’s syntax with support for modern constructs that both simplify the language and make it more accessible to developers who are coming to iOS or OS X development from JavaScript or C#. These developers will find a lot that’s familiar, from the way Swift handles control flow to how it uses functions.

The commonality between Swift and Objective-C simplifies the process of updating apps to the new language. You’re able to mix and match Swift and Objective-C code in the same app, so you can reuse existing libraries in new apps. If you’re moving from the one language to the other, you don’t have to rewrite code you want to reuse, unless you really want to.

Apple’s design principles are focused on safety, and one of Swift’s key features is support for type inference. As a result, while Swift is not strongly typed, it is type safe. If you fail to declare a variable type, but you set the variable to a value that’s already been declared, then Swift infers it’s the declared type. That makes your code safer -- reducing the risk of crashes. Swift also restricts access to pointers with its own memory management.

To continue reading this article register now