Nil-Coalescing Operator
// Declare a constant which has an optional integer type
//
let a: Int? = nil
// Declare a constant with a non-optional integer type,
// which is initialized to `a` if it is non-nil, or 42 otherwise.
//
let b: Int = a ?? 42
// `b` is 42, as `a` is nil// Declare a constant with a non-optional integer type.
//
let a = 1
// Invalid: nil-coalescing operator is applied to a value which has a non-optional type
// (a has the non-optional type `Int`).
//
let b = a ?? 2Last updated