I am new to SWIFT programming and was following Ray Wenderlich's tutorial on collection view. I found code in which they were implementing the collectionView Data source as extensions . I know what are extensions(Extensions add new functionality to an existing class) - But still I can't understand the advantages one is getting while doing such in this scenario.
extension FlickrPhotosViewController : UICollectionViewDataSource {
//1
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return searches.count
}
//2
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return searches[section].searchResults.count
}
//3
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! UICollectionViewCell
cell.backgroundColor = UIColor.blackColor()
// Configure the cell
return cell
}
}
Question - What is the difference in implementing the UICollectionViewDataSource
as -
class FlickrPhotosViewController: UIViewController,UICollectionViewDataSource
And then confirming to the data source delegates. What more advantage do we have when we do it via extensions.Does it provide any other help apart from only making our program structure look good?