The compiler error is not giving too much information here. With your code, imagine self.work
being called parallels, there for, variable hello
will have 2 write access from 2 different threads in a same time which cause data races
as the error indicates. Using MainActor
from your answer helps you eliminate possible of data races
because now there only be one write/read access for Helloworld
variables at one time thanks for Actor
mechanism of protecting share mutable state.