Remove Optional word from optional value in Swift

Swift provides three ways to unwrap the optional :  forced unwrapping, optional binding and checking for nil value manually using if, guard statements, to obtain the value contained in it. When the optional is unwrapped, it always returns the value wrapped by ‘optional’ word. In order to remove the optional word from the optional value in output, Swift provides a instance property named: unsafelyUnwrapped.

When we apply this property on an optional entity ,the output value will not include the optional word wrapped around the value. Accessing this property with nil-value optional will result in serious programming error.

Screen Shot 2018-04-30 at 9.58.26 PM

Leave a Reply