binpress

A Swift Glance at Apple’s New Language

Probably the biggest announcement — from an iOS developer’s point of view — at the Apple Worldwide Developers Conference held in San Francisco 2-6 June, was the introduction of a new programming language, Swift, to replace Objective C. The announcement was a complete surprise and has the potential to radically change the iOS development landscape.

In this blog post, I’m going to explore some of the features of Swift and the impact it will have from a developer’s point of view.

As time goes by, technology advances and languages evolve. This demands a difficult balance as big changes to a language can break backwards compatibility and hamper adoption. However, if a language doesn’t evolve, it can stagnate and become obsolete.

An example of this can be seen with the introduction of Python 3, which breaks compatibility with existing Python code.

This leaves developers with a problem – do they keep developing with the unsupported Python 2, which has thousands of useful third party libraries, or do they start using Python 3, which has a few new features but little in the way of third party support?

This kind of compromise leads to poor adoption which in turn reduces confidence in the updated language.

Apple has dealt with this issue by allowing Swift to run alongside Objective C, in much the same way that Objective C co-exists with C and C++.

This is a clever approach because it allows developers to migrate their code bit by bit while still maintaining compatibility for older programs. The disadvantage is that it can make projects difficult to understand because they mix APIs from a number of different languages.

The first thing that struck me about Swift is that it initially feels like a total departure from Objective C. It’s more similar to JavaScript than it is to C. It takes the best features from a number of modern languages so, like Python, in most cases you don’t need to use a semi colon at the end of a line!

Swift also finally introduces decent string handling. Gone are the days of Objective-C’s

NSString * newString= [NSString stringWithFormat: @“%@ %@”, string1, string2];

When I first saw that, I literally thought “How has Apple developed the iOS using this language?!”

Swift supports concatenation in much the same way as Java, with a plus operator.

There’s also a lot of flexibility about how you name your variables. Swift now supports different languages and character sets – which should boost adoption, especially in China. You can even use emoticons!

let

Author: Ben Smiley

Scroll to Top