presently delete core data item in uicollectionviewcell through tag

蹲街弑〆低调 提交于 2019-12-11 16:46:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!