我正在尝试从coredata中删除一个字符串,我创建了这个函数:
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
self.statusArray.removeAtIndex(indexPath.row)
self.tableView.reloadData()
// Rimuovo da CoreData
var appDel = UIApplication.sharedApplication().delegate as! AppDelegate
var context : NSManagedObjectContext! = appDel.managedObjectContext!
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
let request = NSFetchRequest(entityName: "Status")
request.returnsObjectsAsFaults = false
let result:NSArray = context.executeFetchRequest(request, error: nil)!
context.deleteObject(result[indexPath.row] as! Status)
context.save(nil)
}
}
但实际上当我尝试从tableView中删除某些东西时,这个给了我SIGABRT错误!这个功能出了什么问题?
答案 0 :(得分:0)
请尝试以下示例进行删除。它可能会有所帮助。
var request = NSFetchRequest(entityName: "Status")
var new_sync_details = NSEntityDescription.insertNewObjectForEntityForName("Status", inManagedObjectContext: context) as! NSManagedObject
var err: NSErrorPointer?
if var results = context.executeFetchRequest(request, error: nil) as? [Status] {
println("\nResults count: \(results.count)")
for param in results{
println("\nResults param: \(param)")
new_sync_details.managedObjectContext!.deleteObject(param as NSManagedObject)
}
}