UICollectionView with DiffableDataSource

Rick Aurbach

Xcode 13.1, iOS 25 SDK
I have a UICollectionView (with a custom UICollectionViewLayout) which I am updating with a DiffableDataSource. This CollectionView displays a particular data object (with a given number of sections and items).
The user can choose to display a different object (with a different number of sections and items), reusing this CollectionView. When this occurs, I do the following:
    (pass the new data object to the custom layout)
    let layout = collectionView.collectionViewLayout
    collectionView.contentSize = layout.collectionViewContentSize
    (calculate a new snapshot and apply it)
When the new data object has FEWER sections and/or items as the first, I get a series of warning messages (one for each of the cells that are no longer in the collection view) as follows:
    2021-12-07 14:29:02.239301-0600 WineCorner[82916:1921357] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x7f77b3047e00> index path: (<NSIndexPath: 0xa0f0b1eb018e754a> {length = 2, path = 0 - 4}); frame = (578.118 6; 160 160); transform = [0.70710678118654757, -0.70710678118654746, 0.70710678118654746, 0.70710678118654757, 0, 0]; zIndex = 1;  were received from the layout <WineCorner.WineRackLayout: 0x7f77b1f1a0c0> but are not valid for the data source counts. Attributes will be ignored.
Obviously, I am not handling the situation correctly. What should I do so that these warning messages are not issued?