天天看點

OC基礎之方法和參數的命名規範

以前學過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      

技術改變世界