ckdot ckdot - 1 year ago 35
iOS Question

Why do a lot of methods of the TableViewController just have the name tableView?

I'm currently learning Swift and just implemented my first table.
To fill that table with dynamic data it's necessary to implement a class extending from TableViewController.

Now I'm wondering why some of the configuration methods just have the name tableView, for example:

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool

Why didn't Apple give them names like:

override func getNumberOfRowsInSection(tableView: UITableView, section: Int) -> Int
override func getCellForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath) -> UITableViewCell
override func canEditRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath) -> Bool

I'm sure there is a valid reason for that.


Well I agree with @beyowulf answer which is technically correct.

Objective-C is known for being a choppy/rough language to write with. Using TableView enables users to quickly search up every method related to the UITableViewController instead of typing up the function name to dig through an array of functions to find the one specifically for UITableViewController.

For example if you were to just type cellForItemAtIndexPath you would find the function for UICollectionViewController and UITableViewController. But if you typed tableView first you would only find the functions for UITableViewController.

Its just easier that way and hence why they built it like that.

Hope that clears it up.