Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIván Martínez
11,278 PointsWhy we don't override the methods of UITableViewDataSource in the ContactsDataSourceClass?
Can someone explain this in more detail?
Thank you!
1 Answer
Jason Tjahja
8,668 PointsSince 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