New Swift course

New Swift course

At the Apple Worldwide Developers Conference in 2014, Apple announced the brand new programming language Swift. This new language will alter the landscape of future iOS application development and will eventually replace Objective-C as the language used to develop iOS and Mac applications. Swift is covered in our new course Swift Programming where you will learn the basics of this new language in three days.

Swift incorporates the best features from other, existing languages. For example many concepts of functional programming exist in Swift. Apple will be releasing system libraries that make use of Swift features and certain APIs are only available if you are using Swift. iOS and Mac developers will be needing Swift to stay ahead of competition. The language has seen major development and changes since its release but is now slowly stabilizing.

Swift is a good move for Apple; it makes developing for iOS more attractive. And because Swift, like Objective-C, is only relevant within the Apple ecosystem it encourages developers to commit exclusively to Apple and neglect other platforms. This is clearly a good outcome for Apple, but it’s a bad outcome for developers wanting to engage as many people as possible.

Swift is interoperable with Objective-C. The core system libraries are all written in Objective-C. They make heavy use Objective-C design patterns and conventions and are not ported to Swift. Mixing Objective-C and Swift in a single project is possible and easy. You may call Objective-C code from Swift, and Swift code from Objective-C. Some language features of Swift however are unavailable to the Objective-C consumer, such as Swift struct and enum types. The interoperability means that an existing codebase can be ported to Swift in stages. You don’t have to rewrite the entire app at once. Later you can start to use Swift features that are not part of the Objective-C interoperability.

And there are still certain things that cannot be done in Swift but could be done in Objective-C like an intimate interaction with the runtime. Swift makes it also a lot harder to use reflection and you would better use Objective C for that. Because the Swift language is limited in certain ways optimizations can be made by the compiler which cannot happen in Objective-C. For example, Swift makes use of v-table based polymorphism as well as inlining. In Objective-C this is not possible since you may rip methods out at runtime or change them. Interacting with C APIs is also quite tricky in Swift. It is complicated to pass objects to and from C APIs. Also currently impossible is the creation of a C function pointer to a Swift function. Where Swift lacks in flexibility, it makes up for this in features that don’t exist in Objective-C.

Apple strives to bring Swift to the forefront of iOS development. They emphasize the simplicity of the language and state that anyone can build an iOS app in Swift, even those who have never coded before. However Swift is not the only thing you need to know to develop iOS applications. For the most part, learning Swift is learning a new syntax.

Swift is said to be “safe by default”. One way in which it is safer is that types are much more strict than in Objective-C. In Objective-C, arrays can contain any object. In Swift you declare what type can be stored in the array. The array carries the type information along with it.

Swift certainly has a long road to go but will become the de facto language for iOS and Mac development. With support from the open source community the future of the language will be shaped in the coming years. The near future will be exciting for all iOS and Mac developers.