{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 - Summary of ?, !, and ?? in Optionals

2. Which operator would you use to provide a default value if the value of the optional turns out to be nil?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: ??
Explanation
When an optional value is nil, you can conveniently return a default value by using the ?? operator (Nil Coalescing Operator). var final = chosen ?? default - here if chosen is nil, then the default will get used.
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
Summary of three operators (?, !, ??) used in optionals in Swift.
icon-swift-test.jpg
Tags:
Test on the usage of various Optionals operators (?, !, ??) in Swift

More Articles With Similar Tags
icon-swift-article.jpg
This article discusses the safer ways of unwrapping an optional in Swift that includes Optional Binding.
icon-swift-test.jpg
Test on using Optional Binding in Swift.
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 talks about the Nil Coalescing Operator (??) in Swift.
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.
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map