How to configure UICollectionView supplementary view with data?

I'm trying to shift my current UITableView to UICollectionView with compositional layout and new configuration API.

So UICollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> has two generic types for section and item and two providers

Code Block
public typealias CellProvider = (UICollectionView, IndexPath, ItemIdentifierType) -> UICollectionViewCell?
public typealias SupplementaryViewProvider = (UICollectionView, String, IndexPath) -> UICollectionReusableView?


The problem is that only CellProvider accepts data (ItemIdentifierType) as a parameter and I can configure the cell with it. SupplementaryViewProvider doesn't have SectionIdentifierType in its parameters so I can't understand how to properly configure section header/footer with section data. I don't want to use IndexPath to find necessary section data in some kind of collection view's data array since it is the same approach as previous delegate API.

What is the solution for creating list with custom section headers in new API?
If you need to access your diffable section identifiers from inside the SupplementaryViewProvider closure, you can do that using the snapshot() of the diffable data source. Here is an example, assuming you have your diffable data source stored in a property named dataSource:

Code Block swift
dataSource.supplementaryViewProvider = { [weak self] collectionView, elementKind, indexPath in
    guard let self = self else { return nil }
    let sectionIdentifier = self.dataSource.snapshot().sectionIdentifiers[indexPath.section]
// Dequeue and configure the view...
    return view
}

How to configure UICollectionView supplementary view with data?
 
 
Q