1.10 · Codable, Sendable, macros, ABI

The “platform contract” section: how types cross the wire, cross concurrency domains, and cross module boundaries. Three different kinds of compatibility, often confused.

Mental model. Codable is a compiler-written mapping. Sendable is a boundary promise. ABI is a binary promise. They are independent — a type can be Codable and non-Sendable, or Sendable and not ABI-stable.

Codable

What synthesis gives you and where it stops.

  1. How does Codable synthesis work? When do you write CodingKeys or a custom init(from:)? 1.10.1 · L2
    If every stored property is Codable, the compiler synthesizes Encodable and Decodable using property names as keys. A missing key is allowed for an optional…

Concurrency safety

Promising a type can cross threads.

  1. What does Sendable mean for a Swift type you write? 1.10.2 · L3
    Sendable means the value can cross concurrency domains without a data race. Safe cases: immutable structs/enums of Sendable fields, actors (by identity, since…

Metaprogramming

Three ways to generate code or behaviour.

  1. Macros vs property wrappers vs result builders — one sentence each. 1.10.3 · L3
    Property wrapper — wraps storage and routes get/set through wrappedValue at runtime. Result builder — compiles a block of statements into one expression…

ABI and library evolution

Shipping binaries other apps depend on.

  1. What is ABI stability vs source compatibility vs module stability? 1.10.4 · L5
    Source compatibility — code written against the old API still compiles against the new one. ABI stability — a binary compiled against the old library still…
  2. What does @frozen on an enum mean for you as an API author? 1.10.5 · L5
    @frozen promises the enum will never gain a case. Clients can switch exhaustively without @unknown default, and the compiler can lay out the type with a known…
  3. You need to add a field to a public struct in a binary SPM library used by five apps. What do you consider? 1.10.6 · L8
    First, is the type resilient or @frozen? Resilient (library evolution on, non-frozen) hides layout, so adding a stored property can be ABI-compatible. Frozen…

Setting the bar

Turning all of this into team policy.

  1. How do you set a language bar for a large iOS org (Swift 6, existentials, macros, concurrency)? 1.10.7 · L13
    Make it enforceable, not aspirational: Compiler mode per module, migrating edges inward — start with leaf modules that have no dependents. Lint rules for the…

More in Swift language