What is Sendable?

Asked on 07/31/2024

2 searches

Sendable is a concept in Swift that ensures a type can be safely transferred across concurrency domains without causing data races. A type is considered sendable if it protects its state from concurrent accesses. This is particularly important when dealing with actors and other concurrency features in Swift.

For example, in the session Migrate your app to Swift 6, it is explained that Swift does not infer sendability for public types automatically because marking a type as sendable is a guarantee to your clients that the type contains no mutable state. Therefore, you need to explicitly add sendable conformances on public types.

Additionally, in the session A Swift Tour: Explore Swift’s features and design, it is mentioned that data race safety in Swift 6 is achieved by requiring that values shared between concurrency domains are sendable. This ensures that the values protect their state from concurrent accesses, which is crucial for avoiding crashes or unpredictable behavior in concurrent programming.

Relevant Sessions

  1. Migrate your app to Swift 6
  2. A Swift Tour: Explore Swift’s features and design