Categories
|
Test: Swift - Optional Binding 5. var name = “San Francisco”; if let name=name {print(name)} else {print(“None”)} - what does this print?
Results Congratulations! Correct Answer. You Answered: None. If you took the test, your answer will show up here. Correct Answer: There will be an error Explanation There will be an error. Because the name here is not of Optional type. The variable name is of type String — not String?. For a Conditional Binding / Optional Binding to occur, the variable/constant bound to must be optional. So, if the name is declared as optional, it would work. var name: String? = “San Francisco” — that will work.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 5 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.
|
|
|
|
|