I already know the solution for my problem, but I just really don't understand what's going on here. I have a UITableViewController
that takes the cell in didSelectRow
and uses it for something in an other function. I pass the cell as AnyObject?
. Now when I drill down into a detail VC and then back up again, repeat those steps 2 more times, my app crashes.
First I thought it's a problem somewhere else in my app, but then I created a sample project with nothing but those few lines and managed to reproduce the bug. I also already filed a radar, but I don't want to die dump (as you never hear back form those radar guys) ;) Can anybody explain to me what's going on here!
final class MasterViewController: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let cell = tableView.cellForRow(at: indexPath)
doSomethingWith(sender: cell)
}
}
extension MasterViewController {
func doSomethingWith(sender: AnyObject?) {
// I don't even use that sender!!!
// If the function would read doSomethingWith(sender: Any?) everything would be ok!
}
}
If you want you could download the whole sample at: http://www.georgbachmann.com/demo/CrashTest.zip
I'd really like to know what the swift compiler is doing there!
::EDIT::
I just noted that the crash also depends on doSomethingWith:
being in an extension!