Reputation: 65
I'm writing an iOS app (iOs 14.4.2, Xcode 12.5.1, Realm 5.2.0).
One of the tables I'm using contains cells generated from a "Results" array. The app loads up fine and populates the table correctly with the correct number of cells, correct information, etc.
The problem occurs when I remove a cell from the table (using UISwipeActionsConfiguration). When I print out the number of objects in the results array before and after the action, the number decreases as expected. (For example, if I started with 39 items, it decreases to 38). As long as the bottom of the table is not in view, everything is fine. However, when I scroll to the end of the table, as soon as the final cell is rendered in the UI, the app crashes with an "RLM exception: index is out bounds" error. The stack track shows that the error is being thrown from the "cellForRowAt method". The strange thing is that the realm is saying that the results array should contain 1 LESS than the number of objects shown to be contained in the Results Array.
Does anyone have any idea why this could be? Am I missing something really basic?
Example 1:
Terminating app due to uncaught exception 'RLMException', reason: 'Index 38 is out of bounds (must be less than 38).
Example 2:
Terminating app due to uncaught exception 'RLMException', reason: 'Index 8 is out of bounds (must be less than 8).
2 Questions:
I am running multiple tables in the UI concurrently with the same information presented in different orders based on different parameters, but based on this thread (https://github.com/realm/realm-cocoa/issues/4499), that should not be an issue. (I even tried to hide the other tables, so that only one table is displayed, but the results are the same).
Any help would be greatly appreciated!
Photo of the backtrace, if it helps:
Upvotes: 1
Views: 491
Reputation: 65
I found my issue. I was not updating (and reloading ALL the tables) with the new realm information - and this was important - immediately after Step 2 in both examples (i.e. as part of the same action). Smh.
Upvotes: 0