Is tv an unused variable?


#1

This is in regards to the TahDoodle project. In the first line of the table implementation, “-(NSInteger)numberOfrowsInTableView:(NSTableView *)tv”, what exactly is the tv? After this line, tv never appears again. Maybe there’s something I missed, but I thought that a variable that is declared but never used was an unused variable.


#2

Yes, the table view that you are supplying data to identifies itself when it calls this method.

This is handy when you have multiple table views (For example, you might look at tv and if it is the Department table view, you supply it with data about your list of departments. And if tv is the Employee table view, you supply it with data about your list of employees.)

In this case, however, there is only one table view, so we know it is our task table view, and we just supply the number of tasks.

So the big moral is “Sometimes a helper object will receive data that it doesn’t really need. The guy at Apple who wrote the table view thought you might need it, so he sent it along.”