Core data not being delete permanently through protocol function

My code is trying to delete a element from a set via button. When the user presses the button the set is deleted from that page but if it is reloaded the code is still there. So it is not permanently deleted. All I am doing is trying to delete a element from the core data set. I save the code in one class and iand display it through another. Link to git core-Data-Delete/photography 2.zip at master 路 redrock34/core-Data-Delete 路 GitHub.

extension ViewController : datacollectionProfotocol {
 func deleteData(indx: Int) {

block.reloadData()

let date = users[indx]

users.remove(at: indx)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Item")

request.predicate = NSPredicate(format:"atBATS = %@", date as CVarArg)

let result = try? context.fetch(request)
let resultData = result as! [NSManagedObject]

for object in resultData {
    context.delete(object)
}

do {
    try context.save()
    print(" saved!")
} catch let error as NSError  {
    print("Could not save \(error), \(error.userInfo)")
}

}}

Hiod4

@timswift Do you still have issues with this?

This topic was automatically closed after 166 days. New replies are no longer allowed.