Error:
No ObservableObject of type init(_:content:) found.
A View.environmentObject(_:) for ModelData may be missing
as an ancestor of this view.
Reason: The reason could be that you are missing passing the data from main app
Let’s say the struct is:
@main
struct myApp: App {
@StateObject private var modelData = ModelData()
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
The solution is to pass enviornment object from the parent of your view or from parent app
@main
struct myApp: App {
@StateObject private var modelData = ModelData()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(modelData)
}
}
}