3

I have a UICollectionView with a simple UICollectionViewFlowLayout. On iOS 15 when first loading the view and setting the items an exception occurs.

This is called on the main thread when the items are set:

var snapshot = NSDiffableDataSourceSnapshot<Section, PageItem>()
snapshot.appendSections([.main])
snapshot.appendItems(filteredPages)
dataSource.apply(snapshot, animatingDifferences: true)

I'm getting the following exception:

'the invalidation context ((null)) sent to -[UICollectionViewFlowLayout invalidateLayoutWithContext:] is not an instance of type UICollectionViewFlowLayoutInvalidationContext or a subclass'
terminating with uncaught exception of type NSException

Running the same project on iOS 14 does not crash.

regina_fallangi
  • 2,080
  • 2
  • 18
  • 38
Marcel
  • 6,393
  • 1
  • 30
  • 44

1 Answers1

1

The problem is animating the change, so change from:

dataSource.apply(snapshot, animatingDifferences: true)

to

dataSource.apply(snapshot, animatingDifferences: false)
regina_fallangi
  • 2,080
  • 2
  • 18
  • 38