A lot of online resources say non-final classes are not Sendable by default. That means classes and their properties are not thread-safe. So why is this code not raising an error:
class Counter {
var count = 0
func increment() {
count += 1
}
}
class Tester {
var counter = Counter()
func mutate() {
Task {
counter.increment()
}
}
}
I was expecting an error to be raised at counter.increment()
since counter
isn't Sendable.
Can anyone tell why this code isn't raising an error?