Categories
|
Test: Swift - Nil Coalescing Operator 4. var vowels = [0:”a”, 1:”e”, 2:”i”, 3:”o”, 4:”u”]; var vowel = vowels[5] ?? “a” - What’s in vowel?
Results Congratulations! Correct Answer. You Answered: None. If you took the test, your answer will show up here. Correct Answer: a Explanation In this case, the vowels variable is a dictionary. Dictionary will return nil, if it cannot find the key that is being searched. When ?? sees a nil, it will return the default value provided to it - a in this case. Dictionaries behave differently from Arrays here — if an index is out of range, it would be a fatal error in case of an Array.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 4 of 5
Test is Based on this Article
This article talks about the Nil Coalescing Operator (??) in Swift.
|
Test on Nil Coalescing Operator for Optionals.
|
|
More Articles With Similar Tags
|
Test on Nil Coalescing Operator for Optionals.
|
This article talks about unwrapping the optionals in Swift implicitly and the circumstances where you would use this functionality.
|
This article discusses the safer ways of unwrapping an optional in Swift that includes Optional Binding.
|
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.
|
Summary of three operators (?, !, ??) used in optionals in Swift.
|
|
|
|
|