Thursday, January 18, 2018

What is the use of exclamation mark !?

Highly related to the previous keywords, the ! is used to tell the compiler that I know definitely, this variable/constant contains a value and please use it (i.e. please unwrap the optional). From question 1, the block that executes the if condition is true and calls a forced unwrapping of the optional's value. There is a method for avoiding forced unwrapping which we will cover below.