对于如何删除swift中的所有核心数据,我有点困惑.我创建了一个链接了IBAction
的按钮.点击按钮,我得到以下信息:
let appDel: foodforteethAppDelegate = UIApplication.sharedApplication().delegate as foodforteethAppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext
然后我用各种方法try 删除所有的核心数据内容,但我似乎无法让它正常工作.我使用removeAll从存储数组中删除,但仍然无法从核心数据中删除.我假设我需要某种类型的for循环,但不确定如何根据请求进行.
我try 过应用删除一行的基本原则
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()
}
}
}
然而,问题是,当我点击一个按钮时,我没有indexPath值,而且我需要循环遍历所有的值,这似乎与上下文无关.