一些写代码的常见规范

1.用在.h 文件的@class 和.m文件的#import  替代  .h文件的#import

2.多用字面量 NSNumber *number =@1;替代 NSNumber *number = [NSNumber numberWithInt:1];

3.多用类型常量,少用宏定义

   static nssthring const AnimalTime = 0.3;

   extern NSString *const EOCStringConstant =@"value";

4.多用枚举表示状态,选项。

5.对象内部尽量用实例变量

6.创建多个初始化方法以适应需求。

- (id)initWithFrame:(CGRect)frame

{

    return [self initWithFrame:frame delegate:nil cancelButtonTitle:@"取消" confirmButtonTitle:nil];

}

- (id)initWithFrame:(CGRect)frame delegate:(id<MGJActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle confirmButtonTitle:(NSString *)confirmButtonTitle

{

    self = [super initWithFrame:frame];

    if (self) {

    }

    return self;

}

 

7.非空的写法nil写在前, nil = xxx;

 

8.delegate 在方法前添加必须实现和可选实现的说明@required,@optional

 

posted @ 2016-06-27 14:29  春新  阅读(235)  评论(0编辑  收藏  举报