0Pricing
Swift Academy · Lesson

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

  1. Stack vs Heap: Where Values Live
  2. Mutation, Sharing and Unexpected Aliasing
  3. Mixed Value/Reference Graphs
  4. Designing APIs for Value Semantics
← Back to Swift Academy