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
原文地址:https://www.cnblogs.com/davidgu/p/3912032.html