{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 - Type Inference, Type Safety, and Type Conversion

5. Which of the following will not give an error in Swift?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: let score = Double(“50”); let score:Double; let score = “Nothing”;
Explanation
Only thing that will give error is option A — this is because score does not have a type annotation and since there is no value assigned to it, there is no way to infer the type. In option B, score will be of type Double — it will have a value of 50 that came from the Double(_:String) initializer. Option C makes score a Double, but no value has been assigned — as long as there is a value in this non-optional type before it is used, it will be fine. And finally, in option D, score is inferred to be a String. If a number value (not a String value) gets assigned to this down the road, there will be problems, but there are no problems now.
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 miscellaneous topics and concepts in Swift: Type Inference, Type Aliases, Type Safety, and Type Conversion
icon-swift-test.jpg
This is a test on Type Inference, Type Safety, and Type Conversion in Swift.

More Articles With Similar Tags
icon-swift-series.jpg
This series of articles goes through the basics of Swift. It introduces Playgrounds and REPL; Variables and Constants; Int, Float, Bool; Tuples, Type Aliases, Type Inference, Type Safety, and more.
icon-swift-test.jpg
This is a test on Type Inference, Type Safety, and Type Conversion in Swift.
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map