All posts
iOS

What’s new in Swift 2.2?

Piotr Sochalewski

Piotr Sochalewski

Swift 2.2 is going to be released alongside Xcode 7.3 and is supposed to be sometime in March to May of 2016. This issue is planned to be an intermediate point between Swift 2 and Swift 3 contains more changes. Actually Swift 2.2 only warns you about changes, when Swift 3 would not allow you many things you have got used to. But do not worry – I guess it is another big step in making Swift swifter.

I am going to point out a few most important changes coming to Swift. Right now you can check it out yourself by downloading Swift 2.2 snapshot which works with Xcode 7.2 and 7.3 beta with a little bit of magic. Everything you need to be familiar with recent Swift version you can find on the official website.

Operators

Swift 2.2 gets rid of ++ and -- operators. At first glance I hated that, but in fact it is usually unnecessary to use it in modern Swift. New for loop and higher order functions like map or filter made incrementation unneeded. Of course you can still increment on your own, but in different way.

According to Chris Lattner these increment/decrement operators are confusing, especially if they exists in two forms: as prefix and postfix. In fact I do not remember the last time I had to use ++x, so removing them could make Swift easier to learn as first programming language.

C-style loop

These legacy loops are another carry-over from C. Removing for init; comparison; increment {} lets also remove ++ and -- easily. But do not worry – Swift has really useful pretty for-in loop.

Slices

Wow, I have waited for this for ages. In Swift 2.2 arrays have removeFirst() function. It was easy to make it on your own as extension, but now it is in the box. The function is pretty clever and even if your array can be filled with optionals, it just removes first element, not keep it as nil. Love it.

Tuple comparision

Maybe it is not a breaking news, but weird it was missing. Since Swift 2.2 it is possible to compare tuples containing up to 6 Equatable items.

No more currying

It can break your heart if you actually love curried functions, but I do not. They are reimagined in Swift 2.2 and becomes a little bit more readable.

Check Swift Version

Pretty interesting, but I hope it would not be needed so much. I prefer to refactor my Swift 2 compatible code to Swift 2.2 than supporting both versions (or more). But in some cases it could be useful (i.e. framework that should work with both Swift 2.0 and 2.2 – or even 3.0). Check it out.

Selector

Another macro-style which I do not prefer. Swift 2.2 does not let you specify selector as string itself. In the public review #selector has been chosen rather than Selector() which looks like instance construction (and is also deprecated). In fact it is still better than just string thanks to autocompletion; chances for a typo are minor.

Conclusion

That is not all the changes coming to Swift 2.2, but in my personal opinion most important. From this point I can recommend you Swift’s official changelog (but in fact it is more like a roadmap) and swift-evolution on Apple’s GitHub with all proposals for this evolving language.

I really like where we are now and appreciate coming changes. Swift is modern and brave. You have got to be modern if you want to outgrow Obj-C. You have got to be brave if you want to remove C-style loop being part of this language since 1972. Fingers crossed!

The post is created by Droids On Roids Team Member.
We would love to take care of your project.

Hire US!

Leave comment

  • Husam Aamer

    Thank u , Very good article

  • xyN Cao

    Wow you don’t know the difference between prefix and postfix “++” – you must be new to coding. And Apple sucks too.

    prefix “++” is to never create a temp var to keep previous value. It is more efficient than postfix.

    • Piotr Sochalewski

      I do believe I’ve never wrote that I didn’t know the difference between the two. I simply stated that they can be confusing to newcomer programmers. Thank you for your opinion and take care.