Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Iván Martínez11,278 Points
Why we don't override the methods of UITableViewDataSource in the ContactsDataSourceClass?
Can someone explain this in more detail?
Jason Tjahja8,668 Points
Since in the ContactListController it just inherit to UITableViewController, which if you open UITableViewController, you'll find that it conform to UITableViewDataSource protocol, and remember since it (UITableViewDataSource ) have optional protocols, UITableViewController doesn't need to use the all the methods form the protocol, different form Swift's protocol.
But, that conformance to UITableViewDataSource makes UITableViewController pretend already conform to UITableViewDataSource.
And then, in the ContactListController, since we want to implement methods that UITableViewDataSource protocol has to construct the table, we override those methods because we are in a class that :
first, we just inherit from a class -> UITableViewController and nothing else. And that class which we inherit, conform to UITableViewDataSource. It also pretends to already satisfy requirements of the protocol( UITableViewDataSource) but it doesn't use any of its method.
second, the UITableViewController pretend already conform to UITableViewDataSource protocol, it also tell class that subclass it (ContactListController) that it have those method (that it should satisfy) (once again which it doesn't have any of those -_-) . Because of that, if anyone want to use UITableViewDataSource methods, we need to override it, because now those are method now became UITableViewController's.
conclusion: in the UITableViewDataSourceClass we directly conform to UITableViewDataSource (since it is a protocol) so we don't override those methods