I am seeing the same issue on Xcode 13.2 beta.
After running the code under Xcode 12.5.1, This log message appears:
[Assert] Attempted to scroll the collection view to an out-of-bounds item (0) when there are only 0 items in section 0.
This will become an assert in a future version.
I guess this is the future version when it was decided to assert.
You could try to guard the code from being executed:
guard indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) else {return}
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: