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
)I sincerely believe that the best way to solve a problem is to provide a step-by-step guide or sample code that can 100% reproduce the issue, rather than diagnostic data.
Although I encountered a different issue, I noticed that every time it was related to Preview, the request was always for diagnostic data feedback. I believe this is not very efficient.
Thanks for your feedback! Great idea! A bug report containing all 3 would be even more valuable and increase the odds that it becomes actionable right away, so I do encourage you to file a feedback with as much helpful information as possible, but please do include the diagnostics as it helps answer a lot of questions that a lot of feedback authors may not initially think is important!
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: