Sendable WTF?
A type whose values can safely be passed across concurrency domains by copying.
- Origin
-
Sendable Protocol
- a marker protocol defined in the
Swift
standard library , which has special conformance checking rules.
- protocol Sendable {}
-
It is a good idea for types to conform to the
Sendable protocol when they are designed so all of their public API is
safe to use across concurrency domains
by copying the value.
-
Swift Compiler
- The compiler rejects any attempts to pass data across concurrency domains.
- Misuse
- Incorrect conformance to this protocol can introduce bugs in your program (just as an incorrect implementation of Hashable can break invariants), which is why the compiler checks conformance
- @unchecked conformance
- Any class may be declared to conform to Sendable with an @unchecked conformance, allowing them to be passed between actors without semantic checks
- Actor
- Actor types provide their own internal synchronization, so they implicitly conform to Sendable.