{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 - Implicit Unwrapping of Optionals

5. var score1: Int!; var score2: Int?; score1=10; print(score1+score2) - what does it print?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: Error: optional is not unwrapped
Explanation
Here score1 is automatically unwrapped. And when it’s unwrapped it has a valid integer value of 10. But score2 is Optional Int. That means it needs to be unwrapped. That will be the first problem. If you use print(score1+score2!), you will get to the second issue — nil found after unwrapping. Here score2 has not been initialized to a valid integer value.
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
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-test.jpg
Test on how and when optionals are implicitly unwrapped in Swift.

More Articles With Similar Tags
icon-swift-test.jpg
Test on how and when optionals are implicitly unwrapped in Swift.
icon-swift-test.jpg
Test on Forced Unwrapping of the Optionals in Swift.
icon-swift-article.jpg
This article talks about getting the value wrapped inside an optional by unwrapping it forcibly.
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.
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map