Closed BryanJBryce closed 1 year ago
Hi @BryanJBryce, the StandupsList
view holds onto its observable object like so:
struct StandupsList: View {
@ObservedObject var model: StandupsListModel
…
}
…which makes the parent responsible for providing the model. So it will not be recreated unless the parent decides to recreate it.
And the parent is the app entry point:
@main
struct StandupsApp: App {
var body: some Scene {
WindowGroup {
StandupsList(
model: StandupsListModel()
)
}
}
}
And that shows that only a single model is created for the entire duration of the app.
Also I am going to move this to a discussion since it isn't really an issue with the code sample.
StandupsList
stores its model in anObservedObject
there isn't aStateObject
further up the line, the model is just passed in as a parameter into theView
's init. From what I understand if nothing retains theObservableObject
a new instance is created every time that view redraws its body. Was this intended behavior or left as an exercise to the reader?