MortimerGoro / MGSwipeTableCell

An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.
MIT License
6.96k stars 1.07k forks source link

Retain cycle #256

Open ghost opened 7 years ago

ghost commented 7 years ago

The view controller is being retained because of MGSwipe. Does anyone have the same problem: after one swipe, your view controller never goes to deinit? deinit { print ("deinit \(self)") } Please, can anyone help me? MGSwipeTableCellDelegate is declared as weak, which is good. But maybe something else? Tks!

kolaworld commented 7 years ago

Hey, I also ran into a retain cycle issue while implementing MGSwipeTableCellDelegate in my project. After testing, I traced the retain cycle to the MGSwipeButton class convenience block callback which was retaining the cell responding the block.

I fixed the issue by adding [unowned self] to the block parameter like below:

let undo = MGSwipeButton(title: "Undo", backgroundColor: .red, callback: { [unowned self] (_cell) -> Bool in //do something with _cell return true })

Not sure if this was faulty logic on my part or the block callback but it worked for me.