点击 Build Settings ,然后在搜索框里输入‘macros’
上图可以看出我们已经将该target的宏定义设为TEST,在项目中使用时可以直接使用
#ifdef TEST
NSLog(@"测试环境");
#elif
NSLog(@"其他环境");
#endif
一般Apple已经为我们设置好了 DEBUG 的宏定义,所以,我们只要让 NSLog 在 DEBUG 模式下失效就好了,这样能让我们的程序运行起来更加稳定,同时我们也可以继续使用正规的 NSLog。
//put this in prefix.pch
#ifndef DEBUG
#undef NSLog
#define NSLog(args, ...)
#endif