The Swift Programming Language

The Swift Programming Language

By Jeff Tranter

The preferred programming language for developing on Apple platforms has been Objective-C (1), going back to the 1990s when Apple acquired the NeXTSTEP operating system from which OS X is derived. Like C++, Objective-C adds object-oriented programming support to the C programming language.

In 2014, Apple introduced the new Swift (2) language, which was characterized as "Objective-C without the C". Swift is now being promoted as the replacement for Objective-C and many developers are moving to it for application development on Apple platforms.

As a proprietary language that was only supported on one platform, I didn't find Swift particularly interesting, but in 2015, Apple made Swift available under an Open Source license and added support for Linux platforms (3). While not all library features are supported on the Linux platform, being able to run on additional platforms makes the language much more compelling and worth taking a look.

Some of the key attributes of Swift are:

  • a syntax similar to C and Objective-C
  • memory management based on Automatic Reference Counting
  • compilation to executable code
  • pointers are not exposed by default
  • basic types (like strings) are exposed to the language core and can be used directly

I installed the Linux version of Swift on an Ubuntu desktop system and was able to get some example programs running without any problems.

The Swift Programming Language (4), a 500 page manual, is also available as a free book in ePub format.

The open source version of Swift does not include any of the library classes for GUI development. There has been some discussion about making Qt bindings to Swift once it supports more platforms, but no one has yet stepped forward and announced or demonstrated anything. This should be possible since you can call C++ code from Swift. Some toolkit bindings like Qt on Python use automated tools to generate the bindings. This approach could be used with Swift, which would then expose the full set of Qt APIs that are documented and developers are familiar with.

Summary

C++ has been criticized by some as being an extremely large and complex language that is difficult to learn. However, simpler languages like JavaScript are often not suitable for large or performance-critical applications. Swift may be worth watching as a language that strikes a better balance between performance and scalability to large programs combined with ease of learning and programming.

References

  1. Objective-C, Wikipedia article, last accessed 25 Apr 2016, https://en.wikipedia.org/wiki/Objective-C
  2. Swift (programming language), Wikipedia article, last accessed 25 Apr 2016, https://en.wikipedia.org/wiki/Swift_(programming_language)
  3. Swift community website, last accessed 25 Apr 2016, https://swift.org/
  4. The Swift Programming Language, book in ePub format, last accessed 25 Apr 2016, https://swift.org/documentation/TheSwiftProgrammingLanguage(Swift2.2).epub