#91: Actors in Swift

Actors are Swift’s built-in answer to protecting shared mutable state.

actor Counter {
    private var value = 0

    func increment() {
        value += 1
    }

    func currentValue() -> Int {
        value
    }
}

Because actor state is isolated, outside code usually needs await to access it safely.

That removes a large class of data-race bugs without forcing you to manage locks manually.


I'm also on Twitter and GitHub.

Subscribe via RSS.