// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
Google / Android
Python / IronPython
SQL Server
Test: Swift - Introduction to Optionals

3. var score: Int? - which of the following values can score contain?

Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: 0; nil; 100;
Type of the variable score is Optional, which means, it can hold either a nil value or an Integer value. 0 and 100 are integers, so, they are ok. But 3.4 is either a Float or a Double. It is not an Int. If you assign score = 3.4, Swift will give an error, since there is no automatic conversion between types in Swift.
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 3 of 5

Test is Based on this Article
Tags: optionals, swift
This article talks about the purpose of Optionals in Swift and how to declare them in your code.
Tags: optionals, swift
This is a test on basic concepts of Optionals in Swift.

More Articles With Similar Tags
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.
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.
About  Contact  Privacy Policy  Site Map