{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

4. Which of the following is preferred style in Swift?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: var score = 42; var score:Int;
Explanation
Option A is preferred style in Swift. Since an Int literal has been assigned during the declaration, score will have a type Int. In option B, the type is explicitly mentioned, which is unnecessary. C is also ok, because we might not know at the time of declaration the value of score — but we will assign it before it’s used. But Swift will have to know what the type is, and hence explicit type annotation is needed. D will result in an error, because a Float/Double value is being assigned to Int type.
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
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