i'm new to CoreData and i'm trying to store an entry of a todo list. When i try to creat a new Entry, it would crash. My entity name is "Entry", i selected "Extension" for codegen, but i didn't add any code to the subclass of Entry. what went wrong here? Thank you for helping!
let container: NSPersistentContainer? = (UIApplication.shared.delegate as? AppDelegate)?.persistentContainer
func editOrAdd()
{
if entry?.title != nil {
ifNew = false //edit entry
updateUI()
} else {
ifNew = true //new entry
print(ifNew)
if let context = container?.viewContext {
let newEntry = Entry(context: context) //crashed here
newEntry.creatTime = Date()
try? context.save()
//test
print("new entry creatTime: \(formatter((entry?.creatTime!)!))")
}
}
}
the complete log below
2020-02-14 23:06:43.471370+0800 PriorityList[8876:698237] [error] error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'PriorityList.Entry' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
2020-02-14 23:06:43.475084+0800 PriorityList[8876:698237] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An NSManagedObject of class 'PriorityList.Entry' must have a valid NSEntityDescription.'