Modern SwiftUI: Standups App #141
Replies: 2 comments 2 replies
-
Hi @BryanJBryce, the 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. |
Beta Was this translation helpful? Give feedback.
-
@mbrandonw What's confusing to me is that there is never a |
Beta Was this translation helpful? Give feedback.
-
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?Beta Was this translation helpful? Give feedback.
All reactions