Example of using classes in destination enum in SwiftUI? #326
-
|
What's the recommendation for storing child feature view models inside cases in a navigation destination enum? I’ve pieced together some things, but nothing holistic:
In the swift-navigation example project, I found |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
It's worth calling out that Apple does have some clear guidance on this.
Source: Understanding the navigation stack It also impacts things like restoring the stack later using the Codable representation. You'd have to figure out an alternative way to do that if you needed. |
Beta Was this translation helpful? Give feedback.
Like with most guidance from Apple in SwiftUI, I would take this with a grain of salt. There is nothing fundamentally wrong with doing this. Even the codability works just fine. You will simply encode the bare essentials of the model (such as the ID of the item you are viewing). All other state gets generated once the view appears and the model is interacted with.