Predict the output
The app target uses Xcode 26 defaults (MainActor isolation). A button awaits maker.make(from:). Where does make run?
struct ThumbnailMaker {
func make(from data: Data) async -> UIImage? {
// expensive decode and resize
UIImage(data: data)?.preparingThumbnail(of: .init(width: 300, height: 300))
}
}Hint 1 of 2
What is the default isolation in this target?
Hint 2 of 2
Does async imply a background thread?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: B On the main actor, so the heavy decode can stall the UI
Correct. With default MainActor isolation the struct and its method are main-actor isolated. Mark make @concurrent to move it off.
Why not the others?
- A On a background thread, because the function is async. async means the function can suspend; it says nothing about which thread runs it.
- C On whichever thread happens to be free. Swift concurrency runs isolated code on its actor's executor; for the main actor that is the main thread.
- D On a new thread created for each call. Swift concurrency never creates a thread per call; it uses a fixed pool plus the main thread.