iOS 11 UITableView deleteRows crash

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)

I also have this crash but in my case it's also problematic on iOS 10.3.1. In 10.3.1 the swipe animation does happen but the red delete button is not visible. Using tableView:editActionsForRowAtIndexPath: I've found out that the indexPath of the swiped cell is 18446744073709551615 - 18446744073709551615. I have no idea what is going on.

I don't know if this is the same issue, but I am getting someting very similar from iOS 11. It is when a row is pulled open or tried to be pushed closed. I don't see any way I could fix it.


*** Assertion failure in -[UISwipeActionController swipeHandlerDidBeginSwipe:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.33.6/SwipeActions/UISwipeActionController.m:268

2018-03-13 14:25:59.541863-0700 PersonalAssistantProd[68651:5157265] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No occurrence for index path (null)'

*** First throw call stack:

(

0 CoreFoundation 0x000000011409b12b __exceptionPreprocess + 171

1 libobjc.A.dylib 0x0000000113737f41 objc_exception_throw + 48

2 CoreFoundation 0x00000001140a02f2 +[NSException raise:format:arguments:] + 98

3 Foundation 0x00000001131d8d69 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193

4 UIKit 0x0000000115cdda46 -[UISwipeActionController swipeHandlerDidBeginSwipe:] + 264

5 UIKit 0x0000000115479fb8 -[UISwipeHandler _swipeRecognizerBegan:] + 208

6 UIKit 0x0000000115479ea6 -[UISwipeHandler _swipeRecognizerDidRecognize:] + 91

7 UIKit 0x0000000115485273 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57

8 UIKit 0x000000011548e1aa _UIGestureRecognizerSendTargetActions + 109

9 UIKit 0x000000011548b9ba _UIGestureRecognizerSendActions + 307

10 UIKit 0x000000011548ac26 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1002

11 UIKit 0x000000011546f99c _UIGestureEnvironmentUpdate + 1329

12 UIKit 0x000000011546f41f -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484

13 UIKit 0x000000011546e4cb -[UIGestureEnvironment _updateGesturesForEvent:window:] + 288

14 UIKit 0x0000000114efcf14 -[UIWindow sendEvent:] + 4102

15 UIKit 0x0000000114ea0365 -[UIApplication sendEvent:] + 352

16 UIKit 0x00000001157eca1d __dispatchPreprocessedEventFromEventQueue + 2809

17 UIKit 0x00000001157ef672 __handleEventQueueInternal + 5957

18 CoreFoundation 0x000000011403e101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

19 CoreFoundation 0x00000001140ddf71 __CFRunLoopDoSource0 + 81

20 CoreFoundation 0x0000000114022a19 __CFRunLoopDoSources0 + 185

21 CoreFoundation 0x0000000114021fff __CFRunLoopRun + 1279

22 CoreFoundation 0x0000000114021889 CFRunLoopRunSpecific + 409

23 GraphicsServices 0x000000011a08b9c6 GSEventRunModal + 62

24 UIKit 0x0000000114e845d6 UIApplicationMain + 159

25 PersonalAssistantProd 0x000000010f04ed37 main + 55

26 libdyld.dylib 0x0000000117ccdd81 start + 1

27 ??? 0x0000000000000001 0x0 + 1

)

libc++abi.dylib: terminating with uncaught exception of type NSException

Same issue here.

Seems like similar issue https://forums.developer.apple.com/thread/98184

This issue still exists on iOS 11.4

Being bitten by this right now. Does anyone know if this has been fixed in iOS 12?

I'm still experiencing this issue. Has this been fixed yet?

I also experience this problem, reproducibly after the third deletion in a sequence.


macOS 10.13.6 / Target: iOS 11 / Xcode 9.4.1

It has happened to me in iOS 12 as well.

iOS 11 UITableView deleteRows crash
 
 
Q