Old way:
let foo = "Hello" var bar = String? //nil var result = (bar != nil) ? bar! : foo print("\(result)") //Hello
Pretty nifty. I saw this online someplace. The ?? is called a nil coalescing operator. It’s used to provide a default value when unwrapping an optional type.
let foo = "Hello" var bar = String? //nil var result = bar ?? foo print("\(result)") //Hello