Swift BasicsLesson 8Free preview
Swift Variables
This lesson is part of Swift · All levels
Summary
This lesson reviews the declarations of variables and constants in Swift using the keywords 'let' and 'var'. Swift highly prioritized the principle of immutability: values that were never changed must be declared with 'let'. The Swift compiler will even give automatic warnings if the variable 'var' is never modified.
Key points
- The keyword 'let' is used to declare a constant (immutable)
- The keyword 'var' is used to declare a variable that is changeable (mutable)
- Swift adheres to the principles of type safety and type intelligent inference
- The best practice in Swift is to use 'let' by default unless the value needs to be changed.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.