Practice
Before discussing @MainActor, interviewers often ask candidates to separate "which queue submitted this work" from "which thread is executing it." Run this read-only snippet and use the output to verify the distinction.
After it runs, answer these out loud:
- Why can
serialQueue.syncstill printtrueforThread.isMainThread? - Which part proves that async global work is not on the main thread?
- Why is this still not a substitute for
@MainActorisolation in app code?
Run to compile this snippet and inspect its output. Runs Swift 5.2 on the server (Linux); UIKit, SwiftUI, and long-running async are not supported.