Swift Shortcut: ??

Before the ?? operator was added to Swift, you would use a ternary conditional operator and forced unwrapping to assign a default value if the expected value is nil.

let bossMonster = (monster != nil monster! : defaultMonster) 
// this code says that if monster is not nil then force unwrap monster to get its value, otherwise use defaultMonster

?? provides a shortcut to the above.

let bossMonster = monster ?? defaultMonster

Short and simple! The ?? is known as the nil coalescing operator.

Todd Hopkinson