It’s been around 2 months since WWDC 2014 and the announcement of Swift. Hopefully all you iOS developers out there, novice or otherwise, have taken the time to play around and get to know this new language a bit better.
The problem with learning Swift at the moment is that, exciting as it is, it’s not production ready. There’s still plenty of kinks and a fair amount of ironing out to do and this is evident in the number of beta releases Apple is churning out. We’ve had a new beta almost every two weeks!
With all this change going on, some of the things you learned when Swift was initially released could possibly be different. As a simple example, as of Xcode 6 – Beta 1, to create an array to hold a specific type, say a String, we wrote:
var fruitArray: String = [“apple”, “banana”]
As of Xcode 6 – Beta 3 however, the same thing is achieved by:
var fruitArray: [String] = [“apple”, “banana”]
Note the change from String to [String]. It’s a simple yet major change to how Arrays work.
Keeping up with these changes is very important, especially if you are learning iOS development for the first time through Swift. You don’t want to get stuck while learning, thinking you don’t know how to code, when really Swift syntax has changed and you are unaware of it.
In an attempt to help, here are a set of resources that should help you stay on top of changes as each Beta rolls out and continue learning.
- Swift Programming Language – Document Revision History. The official source for changes to the language.
- Swift In Flux. This repo gives you a quick overview of the different changes in each Beta with links to the discussions in the Apple Developer Forums.
- Airspeed Velocity. Great blog about the Swift language (not iOS or OS X programming) that goes over changes with every Beta. Also covers a lot more in depth topics.
- Swift Blog. The official Swift blog. It doesn’t cover changes as much but does a great job explaining parts of the language.
These links still cover a lot of ground, so if you are a beginner and are coming here from Amit Bijlani’s great Absolute Beginner’s Guide to Swift or Understanding Optionals in Swift posts, here are some of the changes you should be concerned with.
- Swift array type shorthand syntax is written as [SomeType] rather than SomeType
- You can no longer append a single item to an array with the += operator. Instead you need to use the append method (or append a single item array with the += operator).
- When creating Swift dictionaries, you can use the shorthand [KeyType: ValueType] to specify the type of the dictionary.
- Swift now has a section on Access Control. You can use the keywords public, internal and private to restrict parts of your code accordingly.
- Optionals no longer implicitly evaluate to true when a value is present and false otherwise. You need to make explicit checks against nil using the == or != operators.
- Swift introduced a nil coalescing operator (a ?? b) that unwraps an optional if it’s value exists, otherwise returns a default if the optional is nil.
Once you’re comfortable with these changes, make sure to check out the links to go over all the changes to Swift and how it affects your projects!