is actor an enhancement on top of sendable ?

Asked on 12/10/2024

1 search

Actors in Swift are not an enhancement on top of Sendable, but rather a complementary feature that helps manage concurrency and data safety.

Sendable is a protocol that ensures a type can be safely transferred across concurrency domains without risking data races. It is a guarantee that a type's state is protected from concurrent access, either by being immutable or by using synchronization mechanisms.

Actors, on the other hand, are a language feature that automatically manage access to their state by serializing accesses, ensuring that only one task can interact with the actor's state at a time. This makes actors particularly useful for managing shared mutable state safely in concurrent environments.

In summary, while Sendable and actors both contribute to data safety in concurrent Swift code, they serve different purposes. Sendable is about ensuring a type can be safely shared, while actors provide a mechanism to safely manage mutable state.

For more details, you can refer to the session A Swift Tour: Explore Swift’s features and design (21:38).