Home

Introduction

What this book is about, and who it is for

Most Swift tutorials teach you what compiles. This book is about what happens after it compiles — where the value gets copied, which call goes through a vtable, what the compiler had to give up when you reached for a protocol, and why the concurrency checker rejects code that looks perfectly reasonable.

Swift is unusual in how much it hides. A struct assignment might copy a hundred bytes or bump a reference count. A protocol call might be inlined away or might route through a witness table and a heap box. None of that is visible in the source. You can write a great deal of Swift without knowing which is happening — until the day a profile comes back wrong, or a data race appears only on a customer’s phone, and the abstraction stops being free.

Who this is for

You already write Swift daily. You know optionals, closures and if let. What you want now is the layer underneath: not more syntax, but the model that explains why the syntax behaves the way it does.

How it is organised

The chapters build on each other rather than standing alone.

  • Values and references sets up the model everything else rests on: what a copy really costs and why struct is the default.
  • Protocols and Generics are two answers to the same question — how to write code once for many types — with different costs at runtime.
  • Sequences and collections shows what you get by joining Swift’s own protocol hierarchy properly, and what you lose by faking it.
  • Strings is where Unicode stops being someone else’s problem.
  • Memory covers ARC, the cycles it cannot break for you, and the unsafe escape hatches.
  • Concurrency is async/await, actors and Sendable — a type system for time.
  • Performance ties it together: dispatch, allocation, and how to measure instead of guess.

Tip

Every code sample here is meant to be pasted into a playground or a swift REPL and poked at. Reading about a copy-on-write buffer teaches you less in ten minutes than isKnownUniquelyReferenced printing false when you expected true.

A note on versions

Everything here targets Swift 6 and its strict concurrency checking. Where a feature arrived recently — typed throws, parameter packs, sending parameters — the text says so, because a surprising amount of Swift advice online predates them and quietly recommends workarounds for problems the language has since solved.