问题
I am trying to permanently delete a single element from a core data set. Right now the code below removes the core data item but it does not permanently delete it. Once the class is called again it shows up again like nothing happened. I want it permanently deleted.
func loadData() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let fetch = NSFetchRequest<Item>(entityName: "Item")
do {
self.itemName = try managedContext.fetch(fetch)
}
catch {
print("Could not load. \(error)")
}
}
override func viewDidLoad() {
super.viewDidLoad()
loadData()
}
var itemName : [Item] = []
@objc func elete(_ sender:UIButton){
itemName.remove(at: sender.tag)
collectionView.reloadData()
}
来源:https://stackoverflow.com/questions/58313858/presently-delete-core-data-item-in-uicollectionviewcell-through-tag