1.创建预编译文件

2.在工程的TARGETS里边Building Setting中搜索Prefix Header,然后把Precompile Prefix Header右边的NO改为Yes:

3.双击Prefix Header右边白色部分,然后show in Finder 你创建的预编译文件路径,按住拖到白色块里,把根目录改成$(SRCROOT)回车,command+b 运行下,没报错就成功了,如果报错可能根目录不对。




注:一些常用的预编译指令
//在DEBUG模式下打印,并增加所在文件,和转换utf8
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行]:%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif
//颜色(rgb值)
#define LYPColorFramHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue &0xFF0000) >>16))/255.0green:((float)((rgbValue &0xFF00) >>8))/255.0blue:((float)(rgbValue &0xFF))/255.0alpha:1.0]
//颜色(r,g,b)
#define LYPColorFramRGB(r,g,b) [UIColor colorWithRed:(r)/255.0green:(g)/255.0blue:(b)/255.0alpha:1]
//屏幕高
#define Sheight[UIScreen mainScreen].bounds.size.height
//屏幕宽
#define Swidth[UIScreen mainScreen].bounds.size.width//程序总委托
#define appDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
//设计图是按iPhone6尺寸设计的相对于其他屏幕的比例。(放大缩小)
#define V_i6real(f) (((int)(((VSWIDTH * (f*1.f))/375.f)*2))/2.f)
网友评论