Chupamobile Blog

The App Source Code Marketplace. Buy Apps. Sell Apps.

12Jun

It’s obvious that Swift will test current Objective-C developers to adopt this new language but, which of its syntax singularities will really cause headaches to us?

In my opinion one of the Swift ‘s features that developers will find most innovative is class definition and instances creation. I’m not saying that for its complexity but for the disappearance of header files and for the dot syntax to access properties and methods. For example, we’re no longer using:

MyObject *myObject = [MyObject initWithValue:value];

[myObject performAction];

However we’ll use:

var myObject = MyObject()

myObject.performAction()

We have more powerful control flow statements with a cleaner ‘switch’ (no more ‘break’ needed) and ‘for’ loops with range support. They aren’t difficult but they introduce a new syntax that I’m sure we’ll need to re-check during a couple of days.

Now constants should be declared using the ‘let’ keyword and the rest of variables will be declared as “var”, so there is no type specified and they are inferred by default. In case we need to specify the type of a variable or a constant, the right way to proceed is:

var myVar:String = “new var”

You would realize that I’m not using semicolons at the end of the statements because they are no more needed and I think it’s an excellent choice, as it will help us accelerate coding.

Swift is plenty of syntax differences from Objective-C that removes restrictions and allows developers to flow through the code, this is the case of String treatment, but if I had to choose the bogeyman among the new features it would be functions because of its versatility.

With Swift, functions come to life with the possibility of nesting functions, returning another function or multiple values, taking a function or even a variable number of arguments as input. I find it really useful but I must recognize that I will need to restructure my brain to internalize it.

In general Swift gives more freedom when developing but even freedom provokes confusion and hesitation, sometimes is easier obeying orders than taking decisions. In my opinion there are so much restrictions in Objective-C (I don’t blame it, it was created under a different paradigm), that’s why I think of Swift as our particular William Wallace, leading the rebellion to provide us the freedom that was taken from us… ok, I should stop reading Apple documentation.

This is an article by Jorge Jordán, writer and developer for www.insaneplatypusgames.com.