This is a very common question. If you follow the MVC pattern, like all the tutorials and Apple sample code, your view controllers conform to a lot of protocols.
UITableViewDataSource
, UITableViewDelegate
, and UICollectionViewDataSource
, UICollectionViewDelegate
are the most common ones.
If your UI collects user inputs, you also have UIPickerViewDataSource
, UIPickerViewDelegate
, and UITextFieldDelegate
.
What if you show a map? You can count on having MKMapViewDelegate
and CLLocationManagerDelegate
.
Almost all apps fetch data from APIs, so you also have some of these: URLSessionDelegate
, URLSessionTaskDelegate
, URLSessionDataDelegate
, URLSessionDownloadDelegate
.
I can keep going, but let’s just stop here.
Your view controllers conform to many of these Apple provided protocols, plus any custom protocols you define for your app. Each of these protocols has several delegate methods your view controllers need to implement. It can easily get out of hand.
This is one reason contributing to your massive view controllers. Let’s see how Clean Swift tackles this problem.
Continue reading →