You have probably noticed that when we created
collectionview, we set View Controller itself as
collectionView.dataSource = self collectionView.delegate = self
A common pattern found in Cocoa in many components is the delegate pattern, where part of the behavior is delegated to another object, and that object must implement a particular protocol.
In the case of
UICollectionView, and likewise for
UITableView, we have to delegate one of the class references to provide the content for the view,
dataSource, and the other to react to events from the view itself. In this way, the presentation level is completely decoupled from the data and the business logic, which reside in two specialized ...