# How to delete core data item from a uicollectionviewcell using delegation

**URL:** <https://forums.kodeco.com/t/how-to-delete-core-data-item-from-a-uicollectionviewcell-using-delegation/84198>\
**Category:** Swift\
**Created:** [October 8, 2019, 2:53am UTC](https://forums.kodeco.com/t/how-to-delete-core-data-item-from-a-uicollectionviewcell-using-delegation/84198 "2019-10-08T02:53:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timswift](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timswift/32/110937_2.png) [@timswift](https://forums.kodeco.com/u/timswift)\
**Post date:** [October 8, 2019, 2:53am UTC](https://forums.kodeco.com/t/how-to-delete-core-data-item-from-a-uicollectionviewcell-using-delegation/84198/1 "2019-10-08T02:53:50Z")

</div>

my code is trying to peremently delete a item from a core data set. This code works with a basic array like [“sarah”,“Jessica”]. However when trying to delete var itemName I am getting this error Thread 1: EXC\_BAD\_INSTRUCTION (code=EXC\_I386\_INVOP, subcode=0x0) at delegateA?.deleteData(indx: (index?.row)!). I dont know how to permanently delete the core data.All my code below is the parts of the code that function in the delete process.

```
                       class ViewController: UIViewController {
      var itemName : [Item] = []
    var collectionVC = UICollectionView()
  }
    protocol datacollectionProfotocol {
   func deleteData(indx:Int)
    }
  class CustomCell: UICollectionViewCell {
var delegateA: datacollectionProfotocol?
 @objc func ddelete() {
    delegateA?.deleteData(indx: (index?.row)!)
}

}
     extension ViewController: UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCell
          cell.delegateA = self
  }}

```

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 14, 2019, 10:31am UTC](https://forums.kodeco.com/t/how-to-delete-core-data-item-from-a-uicollectionviewcell-using-delegation/84198/2 "2019-11-14T10:31:40Z")

</div>

@timswift Do you still have issues with this?

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [March 22, 2020, 6:56pm UTC](https://forums.kodeco.com/t/how-to-delete-core-data-item-from-a-uicollectionviewcell-using-delegation/84198/3 "2020-03-22T18:56:39Z")

</div>

Closed on March 22, 2020, 6:56pm UTC

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