So I have a table view that lists few items and I have two arrays pointing to the same object that the list holds it in. But the models are the same.
Anyways, I have a delete functionality and while deleting, there is a bug. When I delete the last element, I remove it from the array, but don't call the save api. So if I go back (i.e. pop the view controller from the stack), and come back, the get api will fetch the array and show the list again. But if I press delete again on the last element, it shows index out of range error.
I checked using debugger and I put a breakpoint on the array object (in the model) to see when it gets called (according to this answer - https://stackoverflow.com/a/28117078/5316422). But between the delete confirm button and the actual deletion (during the second attempt), the array is not accessed. I check the value of the array and it has 2 elements. But when I click on the second element (array[1]), it shows the index out of range error and when I check the array, there is only one element. So how does the item in the array get deleted and show 'fatal error: Index out of range'?
Any pointers on how to debug in a more advanced way is also welcome. Thanks