Constants and Variables: Declaring Constants and Variables

Let maximumNumberOfLoginAttempts = 10
var currentLoginAttempt = 0

Additional information

  • Must be declared before they’re used.
  • You can’t declare it again with the same name, or change it to store values of a different type.

Naming Constants and Variables

Let π = 3.14159
let 你好 = "你好世界"
Var friendlyWelcome = "Hello!"
friendlyWelcome = "Bonjour!"
// friendlyWelcome is now "Bonjour!"

Additional information

  • Can contain almost any character, including Unicode characters.
  • Can’t contain whitespace characters, mathematical symbols, arrows, private-use Unicode scalar values, or line- and box-drawing characters.
  • They can't begin with a number, although numbers may be included elsewhere within the name.
  • Avoid using keywords as names unless you have absolutely no choice.
  • Let languageName = "Swift" languageName = "Swift++" // This is a compile-time error: languageName cannot be changed.

Constants and Variables: Declaring Constants and Variables — Structure map

Clickable & Draggable!

Constants and Variables: Declaring Constants and Variables — Related pages: