Inside a navigation view, I have a navigation link that shows the details of the item selected. Every detail view has its own view model. The problem is when I do it this way and check my memory graph I can see all my detail view models have been instantiated and stored in memory even before I make a selection from the list. I'm wondering if this is some sort of a sort UI bug when using the navigation View/Link or if I'm doing something wrong.
Asked
Active
Viewed 147 times
-1
-
https://stackoverflow.com/questions/63006246/swiftui-observedobject-viewmodel-in-detail-view-of-list-never-released/63006377?r=SearchResults#63006377 – lorem ipsum Jun 19 '21 at 01:40
1 Answers
0
Check NavigationLazyView: SwiftUI NavigationLink loads destination view immediately, without clicking
e.g. NavigationLink("SomeLinkLabel", destination: NavigationLazyView(Text("SomeLink"))
edit: been using this for a while, I forgot this is not part of standard SwiftUI

Eric Shieh
- 697
- 5
- 11