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.
- How does
Codablesynthesis work? When do you writeCodingKeysor a custominit(from:)?
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.
- What does
Sendablemean for a Swift type you write?
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.
- Macros vs property wrappers vs result builders — one sentence each.
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.
- What is ABI stability vs source compatibility vs module stability?
Source compatibility — code written against the old API still compiles against the new one. ABI stability — a binary compiled against the old library still… - What does
@frozenon an enum mean for you as an API author?
@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… - You need to add a field to a
public structin a binary SPM library used by five apps. What do you consider?
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.
- How do you set a language bar for a large iOS org (Swift 6, existentials, macros, concurrency)?
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
- 1.1 · Value vs reference types
- 1.2 · Optionals, pattern matching, control flow
- 1.3 · Protocols, extensions, associated types
- 1.4 · Generics, <code>some</code>, <code>any</code>
- 1.5 · Closures, escaping, capture lists
- 1.6 · Properties, observers, wrappers
- 1.7 · Access control
- 1.8 · Error handling, <code>defer</code>, ownership
- 1.9 · Strings and Unicode
- 1.11 · Static vs dynamic dispatch