Declaring Constants and Variables: 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.

Related concepts

Declaring Constants and Variables: Naming Constants and Variables — Structure map

Clickable & Draggable!

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