美文网首页
iOS 代码基本规范

iOS 代码基本规范

作者: RichMartin | 来源:发表于2017-10-17 11:24 被阅读13次

(文章虽然简单 但是实用)
1、先定义nonatomic,再定义具体参数,参数后一个空格接类名,类名后一个空格接 * , * 紧贴变量名。

@property(nullable, nonatomic, readonly, copy) NSString *nibName;

2、方法名前面的 ‘+ -’与方法需要空一格,方法中的赋值号 ‘=’ 左右两边要空一格,或者在某些情况使用符号对齐原则,但同样两边需要空格。

禁止

-(void)gotoRestVC;

请使用

- (void)gotoRestVC;

禁止

contentScrollView.pagingEnabled=YES;
contentScrollView.backgroundColor=[UIColor grayColor];
contentScrollView.showsVerticalScrollIndicator=YES;

请使用

contentScrollView.pagingEnabled = YES;
contentScrollView.backgroundColor = [UIColor grayColor];
contentScrollView.showsVerticalScrollIndicator = YES;

3、文件夹文件首字母大写,方法名首字母小写。

禁止

// 获取休息倒计时
-(NSString *)GetRestCountTime;

-(void)SetRestTimeRemainkeyChain:(NSString *)time;

-(NSString *)GetRestTimeRemainkeyChain;

-(void)RestEnd;

-(void)IsAllowToRest:(BOOL)isAllow;// 3d允许休息

请使用

// 获取休息倒计时
- (NSString *)getRestCountTime;

- (void)setRestTimeRemainkeyChain:(NSString *)time;

- (NSString *)getRestTimeRemainkeyChain;

- (void)restEnd;

- (void)isAllowToRest:(BOOL)isAllow;// 3d允许休息

4、包含头文件,按照 库、扩展、第三方、宏等通用功能、通用类、本类使用的模型或类、控制器、视图方式进行分类排序,其中再以首字母进行排序。

5、单行代码长度尽量不要超过130,使用冒号对齐。
在Xcode > Preferences > Text Editing > Page guide at column:中将最大行长设置为130。

6、成员变量命名开头需加下划线。

禁止

UIScrollView *contentScrollView;
    
UITableView* myTable;
    
NSArray* sectionArray;
NSArray* sectionImageArray;

请使用

UIScrollView *_contentScrollView;
UITableView *_myTable;
    
NSArray *_sectionArray;
NSArray *_sectionImageArray;

7、每个方法之间需要空一行,方法中代码不超过3行时,不需要空行,且方法名后的括号请与方法空一格。

禁止

-(void)close_buttonClick{

    UIViewController *currentVC=[BBUIUtil getCurrentVC];
    [currentVC dismissViewControllerAnimated:YES completion:nil];
    
    [_mvcontentV PlayerPause];
    //游戏恢复正常
    [[BBGameUtil defaultManager]resumeGame];
}


-(void)SetClockType:(AlarmClockType)type{
    
    _mvcontentV.clockType=type;
    
    [_mvcontentV ManagerContentStytle:type];
    
}

请使用

- (void)close_buttonClick {

    UIViewController *currentVC = [BBUIUtil getCurrentVC];
    [currentVC dismissViewControllerAnimated:YES completion:nil];
    
    [_mvcontentV PlayerPause];
    //游戏恢复正常
    [[BBGameUtil defaultManager] resumeGame];
}

- (void)setClockType:(AlarmClockType)type {
    _mvcontentV.clockType = type;
    [_mvcontentV ManagerContentStytle:type];
}

相关文章

网友评论

      本文标题:iOS 代码基本规范

      本文链接:https://www.haomeiwen.com/subject/ugzruxtx.html