Does Swift have a null coalescing operator and if not, what is an example of a custom operator?

As of Swift 2.2 (Xcode 6, beta 5) it’s ??

var x: Int?
var y: Int? = 8

var z: Int = x ?? 9000
// z == 9000

z = y ?? 9001
// z == 8

a ?? b is equivalent to the following code:

a != nil ? a! : b

And as of Beta 6, you can do this:

x ?? y ?? 1 == 8

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)