An Introduction to Swift Programming

June 17, 2014

Very few people who have delved into Apple’s programming domain develop an opinion that one could describe as neutral on the topic of Objective-C. Objective-C draws the ire of many, and the love of a small band. To understand the swift direction away from Objective-C that Apple now follows, one must first understand the nuances of Objective-C that drove the company to create a new language.

The Nuances of Objective-C

On some measurement systems, Objective-C falls in between the minimalistic C++ and the high-level interpreted languages of Ruby and Python. It allows for dynamic binding through message passing by default. Dynamic typing also offers another distinctive feature. Combined with forwarding messages, this ability allows for quick implementations of certain design patterns. Many changes can occur at run-time, especially given Objective-C’s notion of categories – a patch of methods used to extend an existing class.

Many of these features make Objective-C a quirky, but sometimes lovable language. With the sugar comes the bitter taste of many flaws, however. Global namespaces, gruesome syntax for string manipulation, method visibility concerns, and a host of other oddities reveal the language’s age. In short, Objective-C may have lasted until 2014 as a major contender due solely to Apple’s continued support with the contribution of large frameworks that patch many of the pitfalls. What started as a small layer on top of C has grown as a series of patches in the namespace only, and for this reason Apple now crowns a successor.

Enter Swift

Now, let’s dig into what Swift has to offer. A personal favorite of mine, Swift incorporates inferred data types. The “let” keyword allows for the creation of a new form of constant, perfect for use in frameworks, as any Rails enthusiast will quickly point out. From C# and Java, swift brings Coca programming into the modern era with generics. It also uses a new type of hash called a dictionary, which uses similar syntax to its inspiration – JavaScript’s notion of a dictionary.

One of the most frustrating attributes of Objective-C also falls to the wayside, as Swift uses a new string interpolation syntax. Swift allows for the optional use of semicolons, as many modern languages have shown this to be a trivial addition to any compiler. From Python comes the tuple. A tuple allows for simultaneous assignment, a controversial topic in the Python community that swift now enjoys. To round off the list of new features, Objective C allows for the use of closures. An anonymous function that wraps its surrounding context, closures are a hot topic in many circles, and most notably appear in JavaScript as a fundamental building block.

Apple built all of these features into Swift. Unlike Objective-C, these constructs are not frameworks that patch an underlying language, these are embedded language features. Swift does not support message passing as common practice, although the feature does exist. From the list of new features, it may seem apparent that Apple paid close attention to the competition in deciding what to implement in Objective-C’s successor. Swift is a language that fits into the modern mold, and provides enough of change to merit replacing Apple’s old workhorse.

As it was in the past with Objective-C, my opinion gives only modicum weight to the language. If you are interested in developing Apple software you will learn Swift at some time, regardless of its success in popular opinion. I believe, however, that many programmers have found Swift to offer a sleek and modern approach compared to the well worn ancestor. Apple certainly delved deep into the insights that developers learned in the past working with Objective-C, and into the success of other languages. And so, to Objective-C we may not say “Good riddance,” for the sake of so many memories, but at the very least, we may soon say “Goodbye.”