Swift Identifiers
Swift Identifiers
Identifiers name variables, constants, types, functions, etc.
Rules for Identifiers
Identifiers must:
- Start with a letter or underscore.
- May include numbers after the first character.
- Avoid keywords unless escaped with backticks.
They can contain Unicode and must not start with a number.
Escaping Keywords and Unicode
Escape keywords with backticks when needed, and remember identifiers can include Unicode characters.
Example
let `switch` = "ok" // escape a keyword using backticks
let 🐶 = "dog" // Unicode identifier
print(`switch`, 🐶)
Use backticks to escape reserved words in identifiers, and remember Swift identifiers can include Unicode characters.