I am very new to Swift and I would like to remove of the students I have in CoreData from Swift. I have coded this :
let fetchRequest: FetchRequest<Student> = FetchRequest(entity: Student.entity(), sortDescriptors: [])
var students: FetchedResults<Student> { fetchRequest.wrappedValue }
for student in students {
do {
try self.managedObjectContext.delete(student)
} catch {
print("error")
}
}
but it crashes at run-time saying that I have an EXC_BAD_INSTRUCTION on the line where I initialize the students variable. What can I do to make this program correct?
Thanks for your help, Francois