@Observable
final class AppState: Sendable {
enum Stage: Sendable {
case authorizationRequired
case authorized
}
static var shared = AppState()
var currentStage: AppState.Stage
// Warning: Stored property '_currentStage' of 'Sendable'-conforming class 'AppState' is mutable
// … other code
}
@Observable
final class Foo: Sendable {
static let shared = Foo()
var bar: Bool? = nil
}
And I expected the concurrency warning but I am not seeing it. The concurrency warning "Stored property 'bar' of 'Sendable'-conforming class 'Foo' is mutable; this is an error in the Swift 6 language mode" only appears when I remove @Observable.
I'm surprised that Observable would "fix" it, and I'm suspicious as to whether actually does. But I'm having a hard time finding useful information about it.
Btw, in your example I would at least make the reference to the static shared var into static let.
I figured out why @Observable hid the warning. It's because now the warning applies to the code generated by the macro, and won't appear until that code is generated/run.