如何修复线程1:在Xcode 7 swift 2中发出SIGABRT信号?

时间:2015-11-29 06:32:43

标签: ios swift2 xcode7

我正在处理核心数据,当我启动应用程序并单击按钮转到下一页时,它会崩溃并给我这个错误。我不确定如何解决它。

  

由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'NSFetchRequest无法找到实体名称的项目'

的NSEntityDescription
func saveItem(item: String) {
  let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
  let managedContext = appDelegate.managedObjectContext

  let entity = NSEntityDescription.entityForName("Item", inManagedObjectContext: managedContext)
  let Item = NSManagedObject(entity: entity!, insertIntoManagedObjectContext:managedContext)

  Item.setValue(item, forKey: "name")
  var error: NSError?
  do {
    try managedContext.save()
  } catch {
    print(error)
  }
  Items.append(Item)
}

func fetchData() {
  let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
  let managedObjectContext = appDelegate.managedObjectContext

  var fetchRequest = NSFetchRequest(entityName: "Item")
  var error: NSError?
  do {
    let fetchResults = try managedObjectContext.executeFetchRequest(fetchRequest) as? [NSManagedObject]
  } catch {
    print(error)
  }
}

1 个答案:

答案 0 :(得分:-1)

选择.xcdatamodeld文件。

enter image description here