In my tableViewController I have the following. And I am trying to get delete an item to work.
var myData: Array = []
override func tableV
Swift 3.0
Below is the code to delete item and to reload the data.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
let noteEntity = "Note" //Entity Name
let managedContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let note = notes[indexPath.row]
if editingStyle == .delete {
managedContext.delete(note)
do {
try managedContext.save()
} catch let error as NSError {
print("Error While Deleting Note: \(error.userInfo)")
}
}
//Code to Fetch New Data From The DB and Reload Table.
let fetchRequest = NSFetchRequest(entityName: noteEntity)
do {
notes = try managedContext.fetch(fetchRequest) as! [Note]
} catch let error as NSError {
print("Error While Fetching Data From DB: \(error.userInfo)")
}
noteTableView.reloadData()
}