DevPrep

All topics › Swift Concurrency (async/await, actors)

What is a continuation (withCheckedContinuation) and why?

Middle PRO

The essence

A continuation is the bridge from the callback world into async/await. withCheckedContinuation / withCheckedThrowingContinuation suspend the current task, hand you a CheckedContinuation object, and the task resumes when you call resume(returning:) or resume(throwing:). The contract: exactly one resume per continuation. This is how you wrap completion-handler APIs, single-answer delegates, CLLocationManager.requestLocation, SKPaymentQueue and the like.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store