what's sendable ?

Asked on 12/10/2024

1 search

In Swift, "sendable" refers to a type that can be safely transferred across concurrency domains without causing data races. A sendable value is one that protects its state from concurrent accesses, ensuring that it can be shared between different threads or actors without leading to unpredictable behavior or crashes.

In Swift 6, the language enforces data race safety by requiring that values shared between concurrency domains are sendable. This means that for a type to be considered sendable, it must not contain mutable state that could be accessed concurrently. For public types, Swift does not automatically infer sendability, and developers must explicitly mark these types as sendable to guarantee their safety to clients.

For example, if you have a struct with immutable properties, it can be marked as sendable, allowing it to be safely used across different actors. However, if a type contains mutable state or is a reference type, additional considerations or modifications might be necessary to ensure it can be safely marked as sendable.

For more details, you can refer to the session Migrate your app to Swift 6 (32:27) where this concept is discussed.