I'm getting a crash from UICollectionView which may be an Apple bug, but may be my mistake and I'm not sure which.
I have 2 UICollectionViews. I'm dragging a cell from one to another. The goal is users can drag-copy items from one to anther. Since UICollectionView won't give me an indexPath when the user drags an item to the end of a section (and therefore I have no idea to which section they are trying to drag an item (which seems like a major oversight to me) ), when the drag session enters the second collection view, I insert temporary items (that are just "+" icons) on the ends of each section in the second collection view. Thus, the user can drag an item to just before the "+" and my code will add it on the end of the items in that section. I track whether these insertions have been done with a bool so I don't accidentally do it twice. The bool affects the response from numberOfItemsInSection, by adding an extra element, and I instigate the change by calling collectionView.insertItems(at: indexPaths). When the drag session ends or exits, and the bool had been set, I set the bool to false and delete the extra items by calling collectionView.deleteItems(at: indexPaths). When the drag session ends in dropSessionDidEnd instead of dropSessionDidExit, I get the exception: "UIKit internal inconsistency error detected while preparing batch updates map for rebasing.". I've noticed that it crashes after a previous drag session does not result in a drop.
I've always thought that obj-c exceptions when minor mistakes in table and collection animations were crimes by apple against the app community, but this is seriously holding up my app development. But I'm pulling my hair out trying to figure out what's wrong. I can't seriously move forward with this app crashing this way. I wanted to move my NSTableView-based mac app to a UICollectionView-based MacCatalyst app because of how easy it's supossed to be compared to AppKit, but this has turned out to be a nightmare for weeks.
It happens in both MacCatalyst and iOS 13.