This is from Apple documentation on the SwiftUI App protocol:
@main
struct Mail: App {
@StateObject private var model = MailModel()
var body: some Scene {
WindowGroup {
MailViewer()
.environmentObject(model) // Passed through the environment.
}
Settings {
SettingsView(model: model) // Passed as an observed object.
}
}
}
Why do we need to use the @StateObject propertyWrapper in this case? Why isn't a normal property enough?
I suspect that the "App" struct is a configuration object, just like views in SwiftUI? And that we can't count on that struct to hang around once the body has been read? Correct?