Overview - Collection mutability tied to let/var
What is it?
In Swift, whether you can change a collection like an array or dictionary depends on how you declare it. If you use 'let', the collection is constant and cannot be changed after creation. If you use 'var', the collection is variable and you can add, remove, or modify its elements. This rule helps control data safety and predictability in your programs.
Why it matters
This concept exists to prevent accidental changes to data that should stay the same, making programs more reliable and easier to understand. Without this, bugs could happen when data changes unexpectedly, causing crashes or wrong results. It helps programmers clearly show which data can change and which cannot, improving code safety and teamwork.
Where it fits
Before learning this, you should understand basic Swift variables and constants using 'var' and 'let'. After this, you can learn about value types versus reference types, and how mutability affects functions and classes in Swift.