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
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:
previews-diagnostics-0123456789.zip
)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: