Saving core data entity in popover in SwiftUI throws nilError without passing .environment to SubView again

后端 未结 1 2030
傲寒
傲寒 2020-12-30 02:37

Playin\' with SwiftUI and Core Data brought me into a curious problem. So the situation is the following:

I have a main view \"AppView\" and a sub view named \"SubVi

相关标签:
1条回答
  • 2020-12-30 03:11

    WOW THIS DROVE ME NUTS! Especially because the errors tells you absolutely no information as to how to fix.

    Here is the fix until the bug in Xcode is resolved:

            .navigationBarItems(trailing:
                Button(action: {
                    self.add = true
                }, label: {
                    Text("Add Todo List")
                }).sheet(isPresented: $add, content: {
                    AddTodoListView().environment(\.managedObjectContext, managedObjectContext)
                })
            )
    

    Just add .environment(\.managedObjectContext, managedObjectContext) to your secondary view (a Modal, in this example).

    0 讨论(0)
提交回复
热议问题