I am working on an app that combines Core Data with SwiftUI. Everything went well until I put my update code into a sheet, after that I got a "Foundation._GenericObjCError" error of 0 which I believe means no error but my persistent container still didn't get updated.
Is this combination a known problem?
The code I am using to add entries to my Store entry:
struct StoreAdd: View {
@Environment(\.managedObjectContext)
var managedObjectContext
@State
var name = ""
@State
var branch = ""
var body: some View {
VStack {
TextField("Store name", text: $name)
TextField("Store branch", text: $branch)
Button(
action: {
let store = Store(context: self.managedObjectContext)
store.id = UUID()
store.name = self.name
store.branch = self.branch.isEmpty ? nil : self.branch
self.managedObjectContext.persist()
},
label: { Text("Add")}
)
.disabled(name.isEmpty)
}
.padding(.horizontal, 20)
}
}
persist() is a wrapper around save().