我在Swift中有一个简单的代码,当我运行此代码时,Xcode返回一个错误,该错误显示在下面的代码中。有解决方案吗?
我的代码:
import SwiftUI
struct ContentView: View {
@Environment(\.managedObjectContext) var mangedObjectContext
@FetchRequest(fetchRequest: ToDoItem.getAllToDoItems()) var toDoItems:FetchedResults<ToDoItem>
最后一行较高的错误:
线程1:信号SIGABRT
继续代码:
@State private var newToDoItem = ""
var body: some View {
NavigationView{
List{
Section(header: Text("Whats next?")){
HStack{
TextField("New item", text: self.$newToDoItem)
Button(action: {
}){
Image(systemName: "plus.circle.fill")
.foregroundColor(.green)
.imageScale(.large)
}
}
}.font(.headline)
}
}
.navigationBarTitle(("My list"))
.navigationBarItems(trailing: EditButton())
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}
更新
CODE
let contentView = ContentView().environment(\.managedObjectContext, context)