0Pricing
Swift Academy · Lesson

Designing APIs for Value Semantics

Choosing struct vs class when designing public interfaces and frameworks.

Welcome

Designing APIs around value semantics leads to predictable, thread-safe, and easy-to-test code. Let's examine the principles and patterns for making that choice.

The Value Semantics Contract

A type has value semantics if: • Two independent copies are forever independent • Mutating one copy never affects the other • The type behaves like `Int` — `a = b; a += 1` leaves `b` unchanged

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