DevPrep

All topics › AI-assisted development

Swift Concurrency in AI code: why is @unchecked Sendable not a fix?

Senior PRO

Essence

In Swift 6 language mode data races are compile errors. Given an error like "Sending 'x' risks causing data races" or "Main actor-isolated property can not be referenced from a nonisolated context", the model looks for the shortest path to a green build. The shortest paths are @unchecked Sendable, nonisolated(unsafe), @preconcurrency import, MainActor.assumeIsolated or going back to Swift 5 mode. They switch the check off instead of removing the race: the compiler goes quiet and the crash moves to production.

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