我正在处理核心数据,当我启动应用程序并单击按钮转到下一页时,它会崩溃并给我这个错误。我不确定如何解决它。
由于未捕获的异常'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)
}
}