Forced Unwrapping of Optional in Swift

If statements are used to compare the optional value to nil .If there is a value then we can obtain the value stored in the optional by adding ! at the end of the optional type. This is known as forced unwrapping of optional value. Always make sure that the optional has a non-nil value before using forced unwrapping otherwise it will result in runtime error.

 

 

Leave a Reply