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 trial

iOS Enhance a Weather App with Table Views Introduction to Table Views UITableViewDataSource Protocol

Pablo Caro
Pablo Caro
4,191 Points

Help me understand the way this function is written

Im curious as to why the "numberOfRowsInSection" his then followed by section just with a space. Are they two arguments for the function? why isn't there a comma separating them?

code:

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return objects.count }

2 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Pablo Caro,

Parameters can have an external name and a local name in Swift. The local name is for use inside of the function body. The external name is used for the function call. In this case, numberOfRowsInSection is the external name of this function. Therefore, when you call this function, you will use numberOfRowsInSection as the argument name instead of section. You have actually been using external argument names all this time without realizing it. This is because if you do not explicitly specify an external parameter name, Swift will use the local name as the external name, by default.

Hope this helps! Good Luck!

Pablo Caro
Pablo Caro
4,191 Points

Ah yes! I got confused because they have different names...I guess I am still a newbie and hadn't noticed that before! Thanks!!