// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
Google / Android
Python / IronPython
SQL Server
Test: Swift - Optional Binding

1. Which of the following are safe ways to unwrap an optional in Swift?

Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: Checking for nil; Optional Binding;
In both forced and implicit unwrapping, there is no check for nil. Both these case work fine if there is a non-nil value inside the optional. Both of those methods will result in a crash if the optional was never properly initialized and contain nil.

In checking for nil, you will be explicitly checking whether the optional contains nil and will proceed further only then. In Optional Binding, the newly created constant/variable in the if clause will have a non-nil value. If not else block will be executed.
Take the Test
Take the complete test on this topic. You will be able to review answers to questions and get a test score.

Take the Test

Question 1 of 5

Test is Based on this Article
This article discusses the safer ways of unwrapping an optional in Swift that includes Optional Binding.
Test on using Optional Binding in Swift.

More Articles With Similar Tags
Summary of three operators (?, !, ??) used in optionals in Swift.
Test on using Optional Binding in Swift.
This article talks about unwrapping the optionals in Swift implicitly and the circumstances where you would use this functionality.
This article talks about the Nil Coalescing Operator (??) in Swift.
This article talks about optional chaining in swift where multiple optionals can be chained together and fail gracefully by returning nil when one of them is nil.
About  Contact  Privacy Policy  Site Map