Cómo eliminar la fila en la vista de tabla Datos principales. Swift 3
He estado investigando cómo eliminar una fila de una vista de tabla cuyos datos están en Core Data. No puedo encontrar nada en línea que me ayude con mi código. Soy realmente nuevo con Core Data, así que no entiendo mucho.
Gracias por adelantado
Este es mi código
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return}
let managedContext = appDelegate.persistentContainer.viewContext
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "OfficialPT")
fetchRequest.sortDescriptors = [NSSortDescriptor(key:"createdAt",ascending:false)]
do {
AirForceDatabase = try managedContext.fetch(fetchRequest)
} catch let error as NSError {
print("Could not fetch. \(error), \(error.userInfo)")
}
}
func SideMenus ()
{
if revealViewController() != nil {
MenuButton.target = revealViewController()
MenuButton.action = #selector(SWRevealViewController.revealToggle(_:))
revealViewController().rearViewRevealWidth = 275
revealViewController().rightViewRevealWidth = 160
// profileButton.target = revealViewController()
// profileButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
}
Historial de extensionesPTViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
return AirForceDatabase.count
}
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "Cell",for: indexPath) as? HistoryPTTableViewCell {
let person = AirForceDatabase[indexPath.row]
cell.OfficialAbsLbl!.text = person.value(forKeyPath: "officialAbs")! as? String
cell.OfficialPushLbl!.text = person.value(forKeyPath: "officialPush")! as? String
cell.OfficialSitLbl!.text = person.value(forKeyPath: "officialSit")! as? String
cell.OfficialRunLbl!.text = person.value(forKeyPath: "officialRun")! as? String
cell.officialTotal!.text = person.value(forKeyPath: "totalScore")! as? String
cell.officialdateCreated.text = person.value(forKeyPath: "createdAt")! as? String
return cell
}
return UITableViewCell()
}
} extensión HistoryPTViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let person = AirForceDatabase[indexPath.row]
//Convert String to Double
if let score = person.value(forKeyPath: "totalScore")! as? String, let doubleScore = Double(score) {
officialTotalScore = doubleScore
//officialTotalScore = Double(score)
print("Score \(officialTotalScore)")
}
var createdat :String!
CompostiveLbl.text = "Composite Score:\n\(officialTotalScore)%"
createdat = person.value(forKeyPath: "createdAt")! as? String
print(createdat + "CREATED")
if officialTotalScore >= 90 {
print("Excellent")
officialFinalScoreLbl.text = "Fitness Level:\n Excellent"
}else if officialTotalScore >= 75 && officialTotalScore <= 89.9 {
print("Composite Score: Satisfactory")
officialFinalScoreLbl.text = "Fitness Level:\n Satisfactory"
}else if officialTotalScore <= 75 {
print("Composite Score: Unsatisfactory")
officialFinalScoreLbl.text = "Fitness Level:\n Unsatisfactory"
}
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = DateFormatter.Style.long
dateFormatter.dateFormat = "yyyy-MM-dd"
let convertedDate = dateFormatter.date(from: createdat)
dateFormatter.dateFormat = "MMM dd yyyy"
let date = dateFormatter.string(from: convertedDate!)
NextPTLbl.text = "Test Date:\n" + date
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
let person = AirForceDatabase[indexPath.row]
if editingStyle == .delete {
}
}