OC代码基本规范

1.类名的命名

<1>首字母大写,尽量根据类的用途来命名。

AMapLocationManager

<2>工具类、基类可以在最前面加项目的首字母大写。
比如我们的项目是“叮叮约车”--

DDBaseController

<3>语义简洁、明了,不要一大长串。

SpecialCarWaitViewController

2.属性、变量的命名

<1>属性命名时-@property (原子属性, 读写属性, 内存属性);在英文逗号之后加一个空格。

@property (nonatomic, copy, nullable) NSString *title;

<2>类型+空格+*属性名字,属性名字首字母小写,后面单词首字母大写;

@property (nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow;

<3>.m中的变量名字前要加下划线,代表为全局变量。

{
    UIImageView *_imageView;
}

3.方法的命名

<1>有返回值的要把返回内容写在方法名字的最前面。

+ (id)arrayWithArray:(NSArray *)array;

<2>首字母小写,后面单词的首字母要大写,执行性方法以动词开头。

- (void)setImageURL:(ActivityListModel *)model;

<3>+、-号后要加空格,多参数注意回车后冒号对其。

+ (void)showAlertWithMessage:(NSString *)message
           cancelButtonTitle:(NSString *)cancelTitle
           otherButtonTitles:(NSString *)otherTitle
                 andDelegate:(id)delegate
                      andTag:(int)tag;

<4>工具类、基类方法、公有方法要添加注释---快捷键“command+option+/”。私有方法“//”注释就行。

/**
 *  @brief 根据文字字体计算尺寸
 *
 *  @param textString 文字
 *  @param textString 文号
 *  @return 尺寸
 */
+ (CGSize)getTextWidthMethod:(NSString *)textString
           andWordFontOfSize:(NSInteger)size;

你可能感兴趣的:(OC代码基本规范)