Force unwrapping an optional could crash our applications. To eliminate the crashing problem, we can check whether the variable is not nil before unwrapping it.
The following example presents a simple nil checking approach:
if optionalString != nil {
print(optionalString!)
}
This approach is safe in compile and runtime but may cause problems during editing. For instance, if we accidentally move the print line outside the if block, the compiler is not going to complain and it may crash our application during runtime.