100 Days of Swift

100 Days of Swift

Nil-Coalescing Operator

When is it ok to force unwrap a variable?    Only if the variable is not equal to nil. Otherwise you will crash the program.  Make some code that unwraps a value safely.


/**In the above code try changing str to nil

What do you notice? It will print str2 value because str is nil

This checks that str is not nil if is is not nil then it is ok to use str Which is the first option on the left…which is true If false then the

value on the right is used.




Leave a Reply

Name *
Email *