SwiftUI/EnvironmentObject.swift:70: Fatal error: No ObservableObject of type JunkEventStore found. A View.environmentObject(_:) for JunkEventStore may be missing as an ancestor of this view

Hi Everyone, I don't know if this is the right place for this but I am getting this error and I don't know how to fix it.
import SwiftUI

struct StartTabView: View {
(at)EnvironmentObject var myEvents: EventStore
(at)EnvironmentObject var myEventsJunk: JunkEventStore
var body: some View {
TabView{
EventsListView()
.tabItem {
Label("List", systemImage: "list.triangle")
}
EventsJunkView()
.tabItem {
Label("Junk Drawer", systemImage: "tray")
}
EventsCalendarView()
.tabItem {
Label("Calendar", systemImage: "calendar")
}
}
}
}

struct StartTabView_Previews: PreviewProvider {
static var previews: some View {
StartTabView()
.environmentObject(JunkEventStore(preview: true))
.environmentObject(EventStore(preview: true))

}

}'

import Foundation

(at)MainActor
class JunkEventStore:ObservableObject {
(at)Published var events = Junk
(at)Published var preview: Bool
(at)Published var changedEvent: Junk?
(at)Published var movedEvent: Junk?

init(preview: Bool = false) {
    self.preview = preview
    fetchEvents()
}

func fetchEvents() {
    if preview {
        events = Junk.sampleEvents
    } else {
        // load from your persistence store
    }
}

func delete(_ event: Junk) {
    if let index = events.firstIndex(where: {$0.id == event.id}) {
        changedEvent = events.remove(at: index)
    }
}

func add(_ event: Junk) {
    events.append(event)
    changedEvent = event
}

func update(_ event: Junk) {
    if let index = events.firstIndex(where: {$0.id == event.id}) {
        movedEvent = events[index]
        events[index].note = event.note
        events[index].eventType = event.eventType
        changedEvent = event
    }
}

} <

This is my code where I believe the error is happening but please let me know if you need more context!

sorry the formatting is all weird but I copied the code into it

Don't know about your question, but you can paste code between two lines width three back-ticks, like this:

```
struct StartTabView: View {
@EnvironmentObject var myEvents: EventStore
@EnvironmentObject var myEventsJunk: JunkEventStore
...
}
```

…and it will be rendered lit this:

struct StartTabView: View {
  @EnvironmentObject var myEvents: EventStore
  @EnvironmentObject var myEventsJunk: JunkEventStore
  ...
}

Note the three backticks ```

And you can edit the old post to look that code block readable.

I'd add the usual disclaimer: SwiftUI specific topics are better discussed elsewhere (like Apple dev forums or stack overflow) as this forum is focused on topics related to Swift language itself.

Recently we were discussion some SwiftUI – those discussions were related to the new observability machinery for Swift, and as SwiftUI is going to be one of the prominent clients of that new machinery those discussions were on topic. In your example it doesn't seem to be the case.