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

1 Answer 1

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) ...
   }
}
Sign up to request clarification or add additional context in comments.

2 Comments

question, but it's still gonna be evaluated if I remove if from lane 47 and put it on lane 54?
Yes, sure, because TestView_B is recreated in that place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.