Mohammad Azam
Aug 21, 2022

--

Are you talking about EnvironmentObject?

The views that are using EnvironmentObject and are either children of the parent being changed or are part of the navigation stack (and using EnvironmentObject) will be destroyed and recreated.

So, it really depends how many views are using EnvironmentObject and how many views are in the navigation stack (and using EO) at the same time.

One benefit you get from this is that if you change something in the third view and your second view was also using EnvironmentObject then it will update itself and display the updated data automatically when you go back from 3 - 2 view.

If that is causes issues then you can always using @StateObject and not environment object or even slice your EnvironmentObject into multiple environment objects so views that are not interested in the updates will never re-render.

Here is a good example:

https://azamsharp.com/2022/07/01/slicing-environment-object.html

--

--

Mohammad Azam
Mohammad Azam

Written by Mohammad Azam

Lead instructor at a coding bootcamp. Top iOS mobile instructor on Udemy. Author of multiple books and international speaker. azamsharp.school

No responses yet