I'm an Objective-C newbie and a开发者_运维技巧m 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.
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.
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 :)
精彩评论