I'm using SwiftUI
I want to object is call by reference when the screen transitions from ContentView to RemoteController
@ObservedObject became an error with "Cannot assign to property:'self' is immutable"
I want to use the same object for both ContentView and RemoteController
Is there any solution?
Below is the code
struct ContentView: View{ @State var Object : Controller?
@ObservedObject var inputObject : SDController
var body: some View{
NavigationView{
VStack{
Button(action: {
Object = Controller.init(postEventsToMain: true)
inputObject = Object! // error "Cannot assign to property:'self'is immutable"
})
NavigationLink(
destrination: RemoteController()){
RemoteController().environmentObject(inputObject)
}
}
}
}
struct RemoteController:: View{ @EnvironmentObject private var inputObject : Controller
var body: some View{
........
}
}
class Controller: ObservableObject{ ........
init(postEventToMain : Bool = true){
.........
}
}