以前學過C/C++/Java/C#語言的童鞋可能剛開始對於OC的方法和參數的命名規范大為不爽
舉例來說,如下一個OC方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
這個方法,如果在傳統的C++編程語言中
應該是:
void tableViewCommitEditingStyleForRowAtIndexPath( UITableView *tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath *indexPath);
OC為了讓你能更清楚地知道每個參數是派什么用處, 其實是把方法名給拆分了
所以,好的命名規范的建議是:
每個參數名換行,並且讓每個參數后面的冒號盡量對齊(如果不麻煩的話:-))
好的命名規范:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath