3

So, I have few steps, last one contains EnvironmentObject and ObservedObject. The issue is, when I try to modify EnvironmentObject (lane 68) it re-creates ObservedObject. Can any one explain me why this happens? Any solution to keep my ObservedObject with original state?

As far as I know it possible to change ObservedObject to StateObject, but I am using iOS 13+ so... I need other solution.

enter image description here

George Heints
  • 1,303
  • 3
  • 20
  • 37

1 Answers1

2

Line 47 - body is reevaluated so new instance of ObservedStuff is created, so make it as property and pass it in, like

struct TestView_A: View {
   ...
   private let model = ObservedStuff()

   var body: some View {
      NavigationLink(destination: TestView_B(viewModel: self.model) ...
   }
}
Asperi
  • 228,894
  • 20
  • 464
  • 690