CollectionViewDatasourceProtocol is a protocol that is available for you to use when you add a collection view to your screen. It offers three functions; two required and one optional.

The required functions: 

  • collectionView:cellForItem:andSection: This function provides three function arguments. A collectionView, an item, and a section.  In this function, you provide your collection view with the cell to be placed in the specific item position and section. After initializing the cell of your choice, you can set its values as you wish. When you have finished, return your customized cell!
  • collectionView:numberOfItemsInSection: Should return the number of items you wish to be placed in the specific section of your collection view.

The optional functions:

  • numberOfSectionsIn: Should return the number of sections you want your collection view to have.
Did this answer your question?