Test: Swift - Forced Unwrapping of Optionals
4. When do you want to use forced unwrapping (with !) in Swift for further operations on the variable?
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: Only when you are sure there is a non-nil value
ExplanationYou can force unwrap an optional with ! in Swift. An optional can contain nil or a non-nil value. If you force unwrap a nil, then a crash occurs. So, you need to be sure that an optional variable value has been set before force unwrapping it.
Take the TestTake the complete test on this topic. You will be able to review answers to questions and get a test score.
Take the Test
Question 4 of 5