DevPrep

All topics › SwiftUI

Who owns a screen's async work: .task, a Task in the model, refreshable and cancellation?

Senior PRO

The gist

All async work needs an owner whose lifetime matches how long the work is needed. The owner decides when to cancel it. A SwiftUI screen has three levels of ownership:

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