Xcode preview crashes all the time

Hello together, I'm currently learning CoreData, but my preview in Xcode crashes always when I try to add something new to the view. Does someone have an idea what I need to pass to the preview that it works?

My code

Hi,

Sorry to hear you are having problems getting previews working. Could you be hitting this issue listed in the release notes?

Previewing view code in a SwiftData app results in a linker failure for the canvas despite that code compiling successfully for device and simulator. (111657477)
Workaround: Run your app in the simulator to test your UI instead of using Previews.

If not, the best next step will be to file a feedback with diagnostics so we can take a look.

Steps to generate helpful diagnostics:

  1. Download and install the logging profile on all devices involved. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift
  2. Reproduce the issue
  3. Click the "Diagnostics" button in the error banner in Previews' Canvas area (or if the banner is missing you can use the menu: Editor > Canvas > Diagnostics)
  4. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  5. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
  6. Generate the sysdiagnose(s) and attach those too

Hi Thank you all for your swift response and great suggestions.

But I guess the problem isn't Xcode or the preview. I think it has something to do that I dont't pass the CoreData instance the right way. I tried once with the ".environment" but it didn't work. Does someone have an idea?

    @Environment(\.managedObjectContext) var moc
    
    static var previews: some View {
        AddListView()
            .environment(.managedObjectContext, DataController(name: "preview").container.viewContext))
    }
}

This is how the crash looks like:

Xcode preview crashes all the time
 
 
Q