从核心数据中删除记录时,我收到 EXC_BAD_INSTRUCTION 错误
。这是代码:
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
//deleteIncidents()
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
context.delete(candles[indexPath.row] as! NSManagedObject)
candles.removeAtIndex(indexPath.row)
do{
try context.save()
}
catch{
}
//tableView.reloadData()
// remove the deleted item from the `UITableView`
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
最佳答案
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
你使用过这段代码吗?甚至崩溃了。可能是你的谓词有问题,你的谓词之一正在获取空值。你想从具有空值的核心数据中获取数据,而该数据在数据库。
关于ios - 删除 coreData ios 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37672553/