• 1000 1001 *
Вот скриншоты ошибок, которые он выдает
import SwiftUI
struct ContentView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(
entity: TestModelCoreData.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \TestModelCoreData.name, ascending: false)
]
) var entities: FetchedResults<TestModelCoreData>
var body: some View {
VStack {
Text("Hello, world!").padding()
Button(action: {
let newEntry = TestModelCoreData(context: self.moc)
newEntry.name = "New name"
if self.moc.hasChanges {
try? self.moc.save()
}
}) {
Text("Add entry")
}
List(entities, id: \.self) { entity in
Text(entity.name ?? "Unknown")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}