Swift & Concurrency (50 Qs)•Part 2: Concurrency, Actors & Advanced Architecture (11 - 24)
What is Swift 6 Complete Concurrency Checking and how do you migrate legacy code?
senior LevelSystem Design
In Simple Words: Swift 6 enables strict compile-time concurrency checking by default:
- Flags all data races, unsafe global variables, and non-Sendable type sharing across tasks as compiler errors.
- Migration Strategy:
- Enable
-warn-concurrencyin Swift 5.10. - Mark shared reference classes as
actoror wrap in@MainActor. - Ensure closure parameters passed across tasks are annotated with
@Sendable. - Use
@unchecked Sendableas a last resort when wrapping thread-safe C/Obj-C code with manual OS locks (os_unfair_lock).
- Enable