{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Test: Swift - Optional Chaining

2. let options = [1:”to do”, 2:”not to do”]; let option = options[1] - What’s the type of option?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: let option: String?
Explanation
When a value is obtained from a Swift dictionary by using key, the value it returns will be of optional type. So, if the dictionary is of type [Int: String], then the returned value will be of String? type. This is done to facilitate returning a nil value if the key is not found. So, for example, in the above case options[3] will return a nil - a String? type will be able to accommodate this.
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 2 of 5


Test is Based on this Article
icon-swift-article.jpg
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.
icon-swift-test.jpg
Test on optional chaining to safely return a nil or non-nil value from a series of optionals chained together.

More Articles With Similar Tags
icon-swift-test.jpg
Test on optional chaining to safely return a nil or non-nil value from a series of optionals chained together.
icon-swift-article.jpg
This article talks about unwrapping the optionals in Swift implicitly and the circumstances where you would use this functionality.
icon-swift-article.jpg
This article discusses the safer ways of unwrapping an optional in Swift that includes Optional Binding.
icon-swift-article.jpg
This article talks about the Nil Coalescing Operator (??) in Swift.
icon-swift-article.jpg
Summary of three operators (?, !, ??) used in optionals in Swift.
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map