I'm trying to bind a text field value to a core data object and I am getting a Cannot find '$draft' in scope
error. I've tried moving the draft
declaration out of body
, adding @State let
and @State var
to the declaration as well, only to get another error thrown at me saying I can't use property wrappers on local properties.
Is there a correct way to do this?
struct AddItemView: View {
@Environment(\.managedObjectContext) var moc
@Environment (\.presentationMode) var presentationMode
var body: some View {
@State let draft = Item(context: moc)
NavigationView {
HStack {
TextField("Title", text: $draft.title)
}
}
.navigationTitle(Text("Add an Item"))
}
}