iosswiftuicollectionviewuicollectionviewdiffabledatasource

How to create dynamic number of sections in diffable UICollectionView?


I know there is a way to decide the number of sections later on if we use the UICollectionView datasource.

func numberOfSections(in collectionView: UICollectionView) -> Int

Just want to know are there any way for diffable datasource?


Solution

  • The diffable data sources in UIKit and AppKit are declarative.

    This means the framework doesn't ask you for the number of sections, instead you tell the framework the number of sections while preparing the NSDiffableDataSourceSnapshot.