Isn't this a bug?
class ConnectionWatcher : ObservableObject {
static let shared = ConnectionWatcher()
@Published var connected = false
}
struct ConnectedView: View {
@ObservedObject var watcher = ConnectionWatcher.shared
@Binding var connected: Bool
init() {
// compiler error here: ''self' used before all stored properties are initialized
self._connected = $watcher.connected
}
var body: some View {
Text(connected ? "Connected" : "Working offline")
}
}
The compiler is wrong, isn't it? Is there anything I can to initialize this the way I want to?
How the heck do I do this without requiring that someone above me pass in the binding to me?
(And no, I don't want to do an @EnvironmentObject).