I would like two separate ObjservableObject to share a single @Published var.
Ideally something like the below. That does not compile due to Cannot assign to property: '$bar' is immutable. I would like foo and bar to be in sync if a change is made to one or the other.
class FooState: ObservableObject {
@Published var foo: Bool = false
}
class BarState: ObservableObject {
@Published var bar: Bool
init(fooState: FooState) {
self.$bar = fooState.$foo // compile error
}
}
let fooState = FooState()
let barState = BarState(fooState: fooState)
print(fooState.foo) // false
print(barState.bar) // false
fooState.foo = true
print(fooState.foo) // true
print(barState.bar) // true