Xcode Beta 5 was released with several good changes. I don’t want this to just be a “What’s new in Xcode Beta 5” post, because once Beta 6 is released, much less the real language, the only point for a post like that is history. So I am mostly going to talk about my favorite addition to Xcode 6 about optionals, with a short mention of a change that affects it. This great operator is still available in Swift 2.2 (Xcode 7.3) as well!
Nil Coalescing Operator
I did not see this one coming, but I do like it. It basically is a way to easily return an unwrapped optional, or a default value. As with many other parts of optionals, this operator is composed of question marks. Below is a simple example:
var someOptional: Int? = nil var aDefaultValue = 42 var theAnswer = someOptional ?? aDefaultValue
Since someOptional is nil (we didn’t set it to a valid Int yet), theAnswer will of course be 42.
[Read more…]