I am a little confused about how to delete all the main data in swift. I created a button with IBAction . When I click the button, I have the following:
let appDel: foodforteethAppDelegate = UIApplication.sharedApplication().delegate as foodforteethAppDelegate let context: NSManagedObjectContext = appDel.managedObjectContext
Then I mixed up with various methods to try to delete all the main data, but I can not get it to work. I used removeAll to remove from the stored array, but cannot remove from the main data. I assume I need some kind of for loop, but not sure how to do this from the request.
I tried to apply the basic principle of removing one line
func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) { let appDel: foodforteethAppDelegate = UIApplication.sharedApplication().delegate as foodforteethAppDelegate let context:NSManagedObjectContext = appDel.managedObjectContext if editingStyle == UITableViewCellEditingStyle.Delete { if let tv = tblTasks { context.deleteObject(myList[indexPath!.row] as NSManagedObject) myList.removeAtIndex(indexPath!.row) tv.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: UITableViewRowAnimation.Fade) } var error: NSError? = nil if !context.save(&error) { abort() } } }
However, the problem is that when I click the button, I have no indexPath value, and I also need to iterate over all the values ββthat I cannot do with the context.
ios swift core-data
Prateek Jul 09 '14 at 16:06 2014-07-09 16:06
source share