Categories
|
Test: Swift - Optional Chaining 4. let zip = customer.address?.postalCode - Here type of postalCode is Int; and that of address is Address? in the Customer struct. What’s the type of zip?
Results Congratulations! Correct Answer. You Answered: None. If you took the test, your answer will show up here. Correct Answer: let zip: Int? Explanation The last variable in the chain is postalCode — which of type Int. However, in an optional chain, nil also should be accommodated. If the customer doesn’t have an address (since that is optional), the whole expression will return nil. So, for that reason, the type zip will be Int?.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 optional chaining in swift where multiple optionals can be chained together and fail gracefully by returning nil when one of them is nil.
|
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
|
Test on optional chaining to safely return a nil or non-nil value from a series of optionals chained together.
|
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 the Nil Coalescing Operator (??) in Swift.
|
Summary of three operators (?, !, ??) used in optionals in Swift.
|
|
|
|
|