从核心数据删除记录时,我得到EXC_BAD_INSTRUCTION Error
。下面是代码:删除核心数据中的对象ios
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)
}
}
请参阅此链接:http://stackoverflow.com/questions/37559445/how-to-delete-row-from-coredata-entity-ios-swift/37559834#37559834 –