Coding Guidelines for Cocoa


参考:
https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html
http://gracelancy.com/?p=106

http://zh-google-styleguide.readthedocs.org/en/latest/google-objc-styleguide/features/


命名:
骆驼命名法,首字母小写

空格:
Tab键盘:xcode默认4个

a + b; // + - * / , 等符号两边带空格

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@end



函数:
- (void)fuctionName:(id)sender andVarName:(NSString *)var;
- 后面带空格
星号前带空格


括号:
BOOL flag = NO;
    if (flag == NO)
    {
        // 一行也使用一对花括号,规范,实在要好处是方便以后添加代码少敲括号,囧
    }else
    {
    // 花括号使用这种配对
    }


常量
预定义,枚举等使用小写k开头的驼峰法,
比如kInvalidHandle , kWritePerm



注释:
#import <Foundation/Foundation.h>

// 在@interface 上边写注释,
// 两者间距一行

@interface Apple : NSObject
{
    BOOL _flag; // 使用前下划线
}


在比较玄、方法比较陌生、变量名、函数名不容易体现出意思,适当添加注释

尽量使用全称,即使又臭又长


did 已经发生
will 将要发生
Should 是否允许,- (BOOL)redViewShouldHiden;

to  for  with  at 
不要用 and 连接参数,但可以用于说明函数中做了2件事时。
- (void)openFile:(NSString *)path andClear:(BOOL)bool;







你可能感兴趣的:(cocoa)