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

1. You want to enforce name of a product be not changed once it’s assigned. How do you declare productName?

Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: let productName = “Processor X”; let productName: String; productName = “Processor X”;
In Swift, a constant is declared with let. Option B says productName is constant and assigns an initial value of “Processor X”. The value of productName cannot be changed from that point onwards.

Option C is also valid. You can put multiple statements on one line if they are separated by a semi-colon (;). In this option, first the productName is declared as a constant String, then in the next statement a value is assigned.
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 1 of 6

Test is Based on this Article
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.
Test on variables (var) and constants (let) in Swift

More Articles With Similar Tags
Test on variables (var) and constants (let) in Swift
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.
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.
Tags: bool, types, swift
Test on Boolean Types in Swift.
Test on comments, structured comments, and markup in Swift
About  Contact  Privacy Policy  Site Map