Oh dear, Swift 3 sure does change a lot from Swift 2! That’s the bad news…but there is good news! Swift 3 is much easier to read, and therefore type 🙂

Change 1/4 – All Arguments Have Labels

Normally, Swift 2 didn’t require the first arguments label. Swift 3 does. In addition Swift 3 generally truncates the method name and requires you to add it as the first parameter. A good example is the good old Sections in Table View (Swift 2 on top, Swift 3 on bottom).

Another example:

What about methods you’re calling from frameworks such as UIKit? You need to insert an underscore as the first parameter. Eg:

This seems contradictory to the above changes but hey ho, it’s not totally terrible and I’m sure that Xcode 8 will point you in the right direction with lots of handy red errors 🙂

Change 2/4 – Removing Needless Words

Ever thought that Swift 2 was a little too wordy? Eg:

Gee, I wonder if we can squeeze in another ‘Color’ keyword somewhere (!) Swift 3 is determined to eliminate some of that needless length by removing it. Eg:

Finally, an example of the above 2 changes working together:

I kinda like how Swift 3 is making my life easier but I still hate having to change all my existing code (sour grapes).

Change 3/4 – DON’T Use UpperCamelCase for Properties and Enums, DO Use lowerCamelCase

This change helps drive consistency across your code. All properties and enums should be lower camel case. Eg:

So CGColor becomes cgColor. As a property it should be lower camel case (I was originally a C# dev, and we’re always right about camel casing 😉

The same applies to enums, which brings me to Optionals…which are just an enum a la:

“Some” is now “some” but rather than changing code to the lower case version, why not just dump “some” completely by doing the following:

Change 4/4 – Language Changes, You Know, Like Verbs and Nouns

Apple’s getting all existential on us. “Swift 3 is a language so should behave like one”…That means they’re introducing some kind of tenses. Basically, if the method is mutating then use the imperative. If it does not mutate then use the “ed” or “ing” suffix.

Confusing huh? Let’s have an example from Swift 2 that returns an array to the current variable (“array”):

Then Swift 3:

Simple on the face of it but “sort()” in Swift 2 returned a new sorted array, whereas in Swift 3 the same thing returns a sorted array in place! SO WATCH OUT – go through existing code with a fine tooth comb!

Summary

I hope you enjoyed that little snippet of changes to Swift 3. I’ll update this article as and when I find more horrendous code breaking situations!

Where to go Next

This tutorial comes straight out of The Complete iOS Developer Course. Over 40 hours long it contains everything you need to create awe inspiring apps fast!

Click here to check it out!

Changes in Swift 3

Leave a Reply

Your email address will not be published. Required fields are marked *

Share This

Want this Post in Easy to Understand Video Form?

Then get the Complete iOS Developer Course. Over 50 hours of pure Swift coding goodness designed to turn you into a coding master!

One Time Offer - $9! Click to Get it!



WARNING: Once this box is closed the offer will not be shown again.

Thank you!