what is Actor?

Asked on 2025-09-01

1 search

In Swift, an "actor" is a reference type similar to a class, designed to encapsulate shared mutable state while automatically protecting that state by serializing accesses. This means that only a single task can execute at a time on an actor, and calls to actor methods from outside the context of the actor are asynchronous. Actors help in managing concurrency by isolating their data, ensuring that only one thread can access the data at a time, which helps prevent data races.

Actors are particularly useful when you want to move some state from the main actor to a background thread, allowing more code to execute without blocking the main thread, thus keeping the UI responsive. You can define your own actor types, and unlike the main actor, there can be many actor objects in a program, each independent and not tied to a single thread.

For more detailed information, you can refer to the session Embracing Swift concurrency (23:18) from WWDC 2025.