Crashes started occurring in iOS 11. In iOS 10 this works fine.
In a UITableViewCell, when swiping to the left to show the delete button, tapping on it would cause app to crash, with error “UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues: with userInfo (null)”
Interestingly, swiping all the way to the left for the same delete function worked as expected.
Other notes:
- This problem occurs in a UITableViewController. For some reason, in another screen which is a UIViewController subclass that contains a UITableView, a similar delete cell arrangement is implemented and there is no problem with delete button there.
- The problem is quite similar to this one: https://forums.developer.apple.com/thread/81591 however the solution there did not help in my case.
My code looks like:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
..
// Remove a CoreData entity, which triggers the other functions below to be called.
..
}
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.beginUpdates()
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.endUpdates()
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch type {
..
case .delete:
tableView.deleteRows(at: [indexPath!], with: UITableViewRowAnimation.automatic)
..
}
}
Console logs (I added blank lines to make it more readable):
2017-09-26 22:33:35.301878+1000 MyApp[9977:3031908] *** Assertion failure in -[UITableView _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3694.4.18/UITableView.m:6813
2017-09-26 22:33:50.942028+1000 MyApp[9977:3031908] [error]
error: Serious application error.
Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues: with userInfo (null)
CoreData:
error: Serious application error.
Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues: with userInfo (null)
2017-09-26 22:33:50.952682+1000 MyApp[9977:3031908] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:'
*** First throw call stack:
(0x182807d38 0x181d1c528 0x182807c0c 0x183196c24 0x18bf38d84 0x18bdf35f4 0x1005cfed4 0x1005d0494 0x18509d5e0 0x185046ea4 0x185046d78 0x18509c6d8 0x18279a12c 0x1827996cc 0x182799430 0x1828169f4 0x1826d03e0 0x1830f0498 0x184fae348 0x18504ce18 0x184facb04 0x184fab778 0x10053572c 0x100534c44 0x1005d22bc 0x1005d23ac 0x18bf4de6c 0x18bf53ef8 0x18c312e00 0x18c57af90 0x18c57c3a0 0x18c63826c 0x18bc4b20c 0x18bc4b18c 0x18bc35f4c 0x18bc4aa80 0x18bc4a5a0 0x18bc45a70 0x18bc17078 0x18c556f98 0x18c559408 0x18c552574 0x1827b0358 0x1827b02d8 0x1827afb60 0x1827ad738 0x1826ce2d8 0x18455ff84 0x18bc7a880 0x100543cd8 0x1821f256c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)