Daily iOS
Concurrency

class vs actor

In Swift, what's the difference between a class and an actor?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

An actor is a reference type whose access to mutable state is serialized automatically, an isolation domain: from outside you can only reach it with await, and the compiler checks that. A class has no such guarantee, so you have to use locks yourself and the compiler doesn't know when you get it wrong.

Share a question