When I try to a SwiftUI ContentView that contains a CoreData fetch request, the preview crashes. Wondering what the correct way to setup the @environment so the preview can
Credit goes to @ShadowDES - in the Master/Detail template project in Xcode Beta 7 there's a preview that uses Core Data:
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
return ContentView().environment(\.managedObjectContext, context)
}
}
#endif
This works for me in Xcode Beta 5 (my Beta 7 crashes)