i am trying to remove one string from coredata and i created this func:
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)
}
}
but actually this one give me the SIGABRT error when i try to delete something from the tableView! What is wrong with this function?
Try the following example for deleting.It might be helpful.
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)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.