Until 2014, if you wanted to write applications for Apple iOS (the iPhone or iPad), watchOS (the Apple Watch), tvOS (Apple TV), or even a macOS desktop application, the most straightforward way involved using the Xcode IDE with Objective-C as your language. This changed when Apple released a new language, known as Swift. The main advantages it brought were a relative ease of learning, improved safety, along with a more readable and concise programming style.
Let’s take a closer look at Swift to see if it makes sense to use for your team’s Apple programming projects or more.
The development of Swift began inside Apple in 2010, with an internal project team led by Chris Lattner. The language’s first iteration was introduced to the world at Apple’s WWDC in 2014. New versions are typically released in concert with an Xcode update – Swift 3.0 becoming available in September of 2016.
Although originally a proprietary language owned by Apple, Swift entered the open source domain under the Apache 2.0 license in 2015. This also allows developers to target Linux in addition to Apple’s array of platforms. RemObjects Software even makes the Elements compiler that lets Swift code target .NET, Android, and the Java runtime.
Needless to say, the language is growing in popularity, as evidenced by IBM’s website allowing you to write Swift code and quickly see the resultant output. Apple themselves released an iOS app, called Swift Playgrounds, that provides an introduction to the language as well as the practice of programming. It is suitable for anyone from ages 12 to 100.
It is difficult to go into too much depth on a programming language in a simple blog post, but here is a quick overview of some high-level features of Swift. The language syntax is similar to most other object-oriented languages (Objective-C, Java, C#, C++) with the notable absence of semicolons at the end of every line. Object notation using dots is easily understandable by any veteran software engineer.
Automatic memory management is a useful feature, greatly simplifying the coding process. Namespaces, generics, and native error handling (using a try-catch-throw block) are some of the modern language capabilities also provided by Swift. It even supports a few patterns from the functional programming world – most notably, map and filter.
In addition to memory management, a variety of compile-time features help enforce code safety. For example, your code isn’t allowed to set an object to nil; the compiler throws an error in this situation. Xcode also includes a debugging console that provides a built-in interactive version of Swift.
If your team already has a few projects written in Objective-C, you are easily able to use Swift modules within the same codebase. This allows a quick migration to the new language or a mixture of both to leverage the capabilities and experience of your development staff. Finally, the compiler produces high-speed native machine code, providing fast performance to your users on any supported device.
The growing popularity of Swift, even beyond Apple’s proverbial “walled-garden,” makes it worthy of exploration if your shop is writing applications for the desktop or any type of mobile device – from wearables to smartphones. Leveraging Apple’s Swift Playgrounds iPad app or the IBM Swift Sandbox website offers an easy way to perform your own due diligence.
Stay tuned to the Betica Blog for additional dispatches from the wide world of software development. Thanks for reading!