views:

64

answers:

2

I'm an Objective-C newbie and am enjoying reading/learning Objective-C in order to do iPhone development but I'm struggling to understand some of the code, especially the code that comes with the UIKit framework.

For example, take this line:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSelection:(NSInteger)section {
...

I understand the parameters passed in but am struggling to understand the return parameter. Any help appreciated.

+2  A: 

For this particular method, the return type is NSInteger; it is located at the beginning of the method's declaration. See the Objective-C Programming Guide for details on how to declare methods.

The value returned is the number of rows for the given section in a grouped UITableView.

Laurent Etiemble
+1  A: 

In a more C-like pseudo code this could be rewritten as:

 NSInteger returnNumberOfRowsInTableViewSelection(UITableView* tableView, NSInteger section)
{
    ...
}

Contrast with a similar function using simple types:

int add(int a, int b)

NSInteger is the return type, tableView and section are the parameters. You may find the named parameter syntax in ObjC longwinded and confusing at first but in my opinion it leads to much more readable and maintainable code :)

mikecsh