Overview - Structs are value types (copy on assign)
What is it?
In Swift, structs are a way to group related data together. Unlike classes, structs are value types, which means when you assign a struct to a new variable or pass it to a function, Swift makes a copy of the data. This copying behavior ensures each variable has its own independent copy of the data.
Why it matters
This copying behavior helps prevent unexpected changes when multiple parts of a program use the same data. Without value types like structs, changing data in one place could accidentally change it somewhere else, causing bugs that are hard to find. Value types make programs safer and easier to understand.
Where it fits
Before learning about structs as value types, you should understand basic Swift variables and data types. After this, you can learn about classes, which are reference types, to compare how data is shared differently.