Swift & Concurrency (50 Qs)•Part 1: Core Language, Memory & Value Types (1 - 10)
What is the `Sendable` protocol in Swift 6?
junior LevelswiftCore Language
In Simple Words: The cornerstone of Data-Race Safety in Swift 6:
- A
Sendabletype is safe to transfer across concurrency boundaries (between tasks or actors). - What is Sendable?: Value types (structs with Sendable members), Actors, and immutable final classes with immutable properties.
- What is NOT Sendable?: Mutable classes, pointers, closures without
@Sendable. - Swift 6 enforces complete compile-time checking; attempting to pass non-Sendable mutable state across threads triggers a compiler error!