我在appDelegate中收到错误?

时间:2015-07-27 19:06:57

标签: ios xcode swift core-data

当我尝试将待办事项列表应用程序的代码从preCoreData更改为coreData时。

我收到此错误:

'NSInvalidArgumentException',原因:'executeFetchRequest:错误:获取请求必须有实体。'

this is the preCoreData app link

this is the CoreData app link

1 个答案:

答案 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
}