1.合理使用类的前向声明,除非确有必要,否则不要引入头文件; @class
2.定义协议要放入到class-continuation分类中,或单独放到一个文件中;@protocol
3.多用字面量语法,少用与之等价的方法
如字面数值NSNumber *someNumber = @1;
如字面量数组和字面量字典,注意字面量创建的数组和字典是不可变的;
4.多用类型常量,少用#define预处理指令,如
局部使用:
static const NSTimeInterval kAnimationDuration = 0.3;
全局使用:
.h文件中
extern NSString *const EOCStringConstant;
.m文件中
NSString *const EOCStringConstant = @"VALUE";
注意命明规范
5.用枚举表示状态,选项,状态码:
如(不需要组合)
typedef NS_ENUM(NSUInteger, UISystemAnimation)
如(需要组合)
typedef NS_OPTIONS(NSUInteger, UIViewKeyframeAnimationOptions)