当我尝试将待办事项列表应用程序的代码从preCoreData更改为coreData时。
我收到此错误:
'NSInvalidArgumentException',原因:'executeFetchRequest:错误:获取请求必须有实体。'
答案 0 :(得分:0)
我的代码中缺少实体名称
我的代码有错误
func taskFetchRequest() -> NSFetchRequest {
让fetchRequest = NSFetchRequest()
let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
let completedDescriptor = NSSortDescriptor(key: "completed", ascending: true)
fetchRequest.sortDescriptors = [completedDescriptor, sortDescriptor]
return fetchRequest
}
我的代码没有错误
func taskFetchRequest() -> NSFetchRequest {
让fetchRequest = NSFetchRequest(entityName:“TaskModel”)
let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
let completedDescriptor = NSSortDescriptor(key: "completed", ascending: true)
fetchRequest.sortDescriptors = [completedDescriptor, sortDescriptor]
return fetchRequest
}