{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 - Variables and Constants

6. Which of the following is the preferred way in declaring a variable in Swift?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: var name = “infiniteZest.com”
Explanation
While both are accurate, with option B, Swift can figure out (type inference) the type of the variable name. By looking at the string value assigned to it, Swift can say, name is of type String. That makes the code smaller and cleaner without losing any clarity. Hence, option B is the preferred way of declaring variables or constants 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 6 of 6


Test is Based on this Article
icon-swift-article.jpg
This article talks about variables and constants and how Swift forces you to choose var (a variable) or let (a constant) right at the time of declaration.
icon-swift-test.jpg
Test on variables (var) and constants (let) in Swift

More Articles With Similar Tags
icon-swift-test.jpg
Test on variables (var) and constants (let) in Swift
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-article.jpg
Tags: bool, types, swift
This article discusses the boolean types in Swift and contrasts with how these types are used in C and Objective-C.
icon-swift-test.jpg
Tags: bool, types, swift
Test on Boolean Types in Swift.
icon-swift-test.jpg
Test on comments, structured comments, and markup in Swift
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map