25. November 2016
Using the nil-coalescing operator
The nil-coalescing operator ??
lets you provide a default value while trying to unwrap an optional. You use it like this:
let colors: [UIColor] = []
let red = colors.first ?? .red
print(red)
This often eliminates the need for if let
or guard
statement.