Swift concurrency
Swift Concurrency Interview Guide
The interview map for explaining correctness over time, across tasks, actors and suspension points.
Short answer
What matters most
A senior Swift concurrency answer should explain ownership, lifetime, cancellation, isolation and what may change across every await. Async and await describe suspension, not automatic background execution. Actors serialize access to isolated state, but reentrancy means an invariant can still become stale while an actor method is suspended. Cancellation is cooperative, so work must observe it. MainActor is the boundary for UI state, not a place to hide expensive computation. Sendable asks whether a value can safely cross isolation domains. In an interview, connect each concept to production behavior: stale search results, reused image cells, duplicated requests, background saves, UI updates and race-free caches. The strongest answer states the safe default, the nearest alternative and the condition that changes the decision.
The six questions to ask
When reading concurrent code, do not begin with syntax. Trace the work through time and identify the invariant it must protect.
- Who creates and owns the task?
- What ends or cancels it?
- Which mutable state does it touch?
- What can change while it is suspended?
- Which isolation boundary does data cross?
- How does the UI remain truthful if work finishes late?
Actors and reentrancy
An actor prevents simultaneous access to isolated state, but it can process other work while a method awaits. Code that reads state, awaits a response and writes using the old value can still be logically wrong.
Explain the invariant, then choose a repair: snapshot immutable input, revalidate after suspension, separate phases or redesign the state transition so stale work cannot commit.
Practice scenarios
Use search, image loading, pagination, authentication refresh and offline synchronization. For each one, draw task ownership, cancellation and the final UI state.
Then explain how you would test ordering and cancellation deterministically. That turns definitions into engineering judgment.