Sean Sean - 1 year ago 56
Swift Question

When calling a function in Swift, what does each part mean?

For example, if I am writing:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

what does
_tableView: UITableView
, and
didSelectRowAt indexPath: IndexPath
each refer to in general terms?

Answer Source

The first tableView is the method name. Then, inside the parentheses are parameters, separated by commas. Each parameter has three parts: the external name, the internal name, and the type. If the external name (the name of the parameter used by code calling the method) is the same as the internal name (the name of the parameter used by code inside the method), you can replace it with an underscore (_). So, the first parameter has an internal and external name of tableView. The part after the colon (:) is the type, the first parameter has a type of UITableView. The second parameter has an external name of didSelectRowAt, an internal name of indexPath, and a type of IndexPath.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download