UICollectionViewDataSource
The methods adopted by the object you use to manage data and provide cells for a collection view.
Declaration
@MainActor protocol UICollectionViewDataSource : NSObjectProtocolOverview
A data source object manages the data in your collection view. It represents your app’s data model and vends information to the collection view as needed. It also creates and configures the cells and supplementary views that the collection view uses to display your data.
A collection view data source must conform to the UICollectionViewDataSource protocol. You can use a UICollectionViewDiffableDataSource object as your data source object, which already conforms to this protocol.
Alternatively, you can create a custom data source object by adopting the UICollectionViewDataSource protocol. At a minimum, all data source objects must implement the collectionView(_:numberOfItemsInSection:) and collectionView(_:cellForItemAt:) methods. These methods are responsible for returning the number of items in the collection view along with the items themselves. The remaining methods of the protocol are optional and only needed if your collection view organizes items into multiple sections or provides headers and footers for a given section.
When you configure the collection view object, assign your data source to its dataSource property. For more information about how a collection view works with its data source to present content, see UICollectionView.