Skip to content

Instantly share code, notes, and snippets.

@DiganVaghasiya
Created October 23, 2020 12:37
Show Gist options
  • Select an option

  • Save DiganVaghasiya/670fc0119e03ab503ce65ac47a620642 to your computer and use it in GitHub Desktop.

Select an option

Save DiganVaghasiya/670fc0119e03ab503ce65ac47a620642 to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
{
if editingStyle == .delete
{
self.deleteDicData(index: indexPath.row)
tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.automatic)
}
}
The deleteDicData(index: indexPath.row) , send swiped cell indexpath in this function , and the function code is :
func deleteDicData(index:Int)
{
let dictionary = NSDictionary(contentsOfFile: self.getpath())
var arrEmployee = dictionary?.value(forKey: "arrEmployee") as! [[String:Any]]
arrEmployee.remove(at: index)
dictionary?.setValue(arrEmployee, forKey: "arrEmployee")
let plistContent = NSDictionary(dictionary: dictionary!)
let success:Bool = plistContent.write(toFile: self.getpath(), atomically: true)
if success {
self.arrEmployee = arrEmployee
if arrEmployee.count == 0 {
lblNoData.isHidden = false
}
else{
lblNoData.isHidden = true
}
}
else
{
print("Not written")
}
// self.dataTableView.reloadData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment