Actor or sendable? When is appropriate?

Viewed 8

The following code errors because the var is not allowed.

final class Article: Sendable {

    let title: String
    var likeCount = 0

    init(title: String) {
        self.title = title
    }
}

Changing the above to a struct solves the problem. But my question is why not use an actor here instead of a struct?

actor Article {

    let title: String
    var likeCount = 0

    init(title: String) {
        self.title = title
    }
}

This post about using actors in Scala seems to highlight two cases where actors are conceptually not appropriate.

So might it be safe to say that we should use an actor (instead of a struct) as a default option, until it becomes inappropriate to do so?

0 Answers
Related