How do I pass the child view to the ancestor view
ERROR ON ForEach = Thread 1: Fatal error: No ObservableObject of type MenuListFriendshipModel found. A View.environmentObject(_:) for MenuListFriendshipModel may be missing as an ancestor of this view.
ERROR ON List = Thread 1: Fatal error: No ObservableObject of type MenuListFriendshipModel found. A View.environmentObject(_:) for MenuListFriendshipModel may be missing as an ancestor of this view.
// ListView.swift
import SwiftUI
struct FriendshipListView: View {
@EnvironmentObject var listViewModel: MenuListFriendshipModel
var body: some View {
List {
//Use the $ syntax to pass a binding on to the subviews
ForEach($listViewModel.items) { $item in
MenuListRowView(item: $item)
}
}
.navigationTitle("Friendships / Relationships")
.listStyle(PlainListStyle())
}
}
struct ListView_Previews: PreviewProvider {
static var previews: some View {
FriendshipListView()
.environmentObject(MenuListFriendshipModel())
}
}
ERROR ON = Thread 1: Fatal error: No ObservableObject of type MenuListFriendshipModel found. A View.environmentObject(_:) for MenuListFriendshipModel may be missing as an ancestor of this view.
// ManifestationMenuApp.swift
import SwiftUI
@main
struct ManifestationMenuApp: App {
@AppStorage("isOnboarding") var isOnboarding: Bool = true
var body: some Scene {
WindowGroup {
if isOnboarding {
OnboardingView()
} else {
MainView()
}
}
}
}