在我们开发过程中,经常使用到预编译的宏定义,例如 OC 代码中 #ifdef DEBUG
这种宏定义的,还有多个 Target 有些公用的地方某部分代码不用,也会用到宏预编译。
OC 预编译宏定义

这样就可以在 OC 代码中使用
#ifdef UAT // UAT 对应的 target
//code
#elif SIT // SIT 对应的 target
//code
#else // PRD 对应的 target
//code
#endif
Swift 预编译宏定义
Swift 与 OC 不同,定义位置不同

这样就可以在 Swift 代码中使用
#if UAT // UAT 对应的 target
//code
#elseif SIT // SIT 对应的 target
//code
#else // PRD 对应的 target
//code
#endif
注意
- 如果是 OC 和 Swift 代码混编,都用到了,就需要两个位置都设置
网友评论