然后,将Precomplie Prefix Header
选项改为YES
,这样pch
会被预编译,预编译后的pch
文件会被缓存起来,从而提高编译速度。
双击Prefix Header
右侧的空白项,会弹出一个小窗,输入下面的路径字符串,会自动替换你的工程实际路径名称。
$(SRCROOT)/$(PROJECT_NAME)/PrefixHeader.pch
例如:
$(SRCROOT)/DEMO-APP/DEMO-APP-Header.pch
Command+B
编译一下程序,看是否会报错。如果有错误,检查下路径是否添加正确。
至此,PrefixHeader.pch
文件配置完成。
三、PrefixHeader.pch 文件讲解
注1⚠️:因为 pch
文件在预编译后会将头文件缓存起来,再次编译时则不需要重新编译该文件中的内容,进而提升了编译速率。所以尽量不要将开发中共用性较低的文件或宏定义(宏定义可单独创建一个头文件进行存放,再将该宏文件引入至 pch
)引入进 pch
文件中导致重复编译的操作,反而降低其速率使文件所带来的作用大大折扣。
注2⚠️:pch
文件的命名方式,建议以项目名称开头,例如项目名称为"TestDemo"则 pch 文件名称则为"TestDemo-Prefix
",当然实际命名以用途为准。
.pch
文件示例如下:
//
// Hello-Header.pch
//
#ifndef Hello\_Header\_pch
#define Hello\_Header\_pch
#define WEAKSELF typeof(self) \_\_weak weakSelf = self;
#define STRONGSELF typeof(self) \_\_strong strongSelf = self;
#define STRONGSELFFor(object) typeof(object) \_\_strong strongSelf = object;
#define kScreen [UIScreen mainScreen].bounds.size
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define HexCorlor(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0 green:((float)((hexValue & 0xFF00) >> 8)) / 255.0 blue:((float)(hexValue & 0xFF)) / 255.0 alpha:1.0]
#define DEFAULTFRAME CGRectMake(0, 0, 1, 1)
#define BIGHEIGHT kScreen.width\*9/16
#define SMALLHEIGHT (kScreen.width/2)\*9/16
#define is\_iPhoneXSerious ({\
BOOL isPhoneX = NO;\
if (@available(iOS 11.0, \*)) {\
UIWindow \*window = [[UIApplication sharedApplication].windows firstObject];\
isPhoneX = window.safeAreaInsets.bottom > 0;\
}\
isPhoneX;\
})
#define is\_portrait ({\
BOOL is\_portrait = NO;\
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;\
is\_portrait = !UIInterfaceOrientationIsLandscape(orientation);\
is\_portrait;\
})
#define STATUS\_BAR\_HEIGHT (is\_iPhoneXSerious ? 44.f : 20.f)
#define NAVIGATION\_BAR\_HEIGHT (is\_iPhoneXSerious ? 88.f : 64.f)
#define TAB\_BAR\_HEIGHT (is\_iPhoneXSerious ? (49.f+34.f) : 49.f)
#define HOMEINDICATOR\_HEIGHT (is\_iPhoneXSerious ? 34.f : 0)
#define KViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setShouldRasterize:YES];\
[View.layer setRasterizationScale:[UIScreen mainScreen].scale];
#define KViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setShouldRasterize:YES];\
[View.layer setRasterizationScale:[UIScreen mainScreen].scale];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]];
// notifacation
#define K\_NOTIC\_CENTER [NSNotificationCenter defaultCenter]
#define K\_Notic\_LogOutNative @"K\_Notic\_LogOutNative"
#define K\_Notic\_LoginSuccess @"K\_Notic\_LoginSuccess"
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
### 最后
**[开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/topics/618166371)**
reference this file.
### 最后
**[开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/topics/618166371)**
>![](https://img-blog.csdnimg.cn/img_convert/e2b2196a60b50995cc6d819220b18d75.webp?x-oss-process=image/format,png)