Mutation, Sharing and Unexpected Aliasing
How shared references cause bugs and how value types prevent them.
Welcome
Aliasing occurs when two variables refer to the same object. With value types it's impossible; with reference types it leads to surprising bugs. Understanding this distinction is key.
Value Types Have No Aliasing
```swift
var a = [1,2,3]
var b = a // independent copy
a.append(4)
print(b) // [1,2,3] — unchanged
```
Every assignment of a value type creates an independent copy.
All lessons in this course
- Stack vs Heap: Where Values Live
- Mutation, Sharing and Unexpected Aliasing
- Mixed Value/Reference Graphs
- Designing APIs for Value Semantics