ios - 删除 coreData ios 中的对象

标签 ios swift uitableview core-data

从核心数据中删除记录时,我收到 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/

相关文章:

iOS/swift : InAppPurchase invalidProductIdentifiers

swift - 是否可以将 UILabel 文本的常规字体更改为粗体?

swift - UITableView 滚动到顶部

ios - SecPKCS12Import 不返回任何项目

ios - 适用于 iOS 的 Google Calendar API 返回生日?

ios - 如何使用 AVAssetWriter 制作缩小尺寸的视频?

ios - NSNumberFormatter.string(来自 : ) maximum possible Value exceeded does not result in Overflow - Swift

swift - UItableView 无法快速重新加载数据

iOS drawRect 没有正确读取颜色属性

ios - 如何比较数组?还有改变属性?