xcode 设置 Build Configuration
2018-05-26 本文已影响199人
壹点微尘
xcode 默认 情况下只有Debug
和 release
两种模式:

一般情况下公司后台服务器会有三种情况: dev 、test、release 环境,
xcode自带的两种模式, 已经满足不了要求了, 好在xcode可以自定义添加配置, 具体配置如下:
第一步: 按下图, 在5
处 选择Duplicate "debuge" Configuration
. 因release模型是不支持断点调试,最好不要使用.

第二步: 在蓝色框框处, 写上你想要的名字, 然后回车

这时候,如果我们再去切换编译模式, 就会发现多出了一个Test

第三步: 设置 Preprocessor Macros
在 target / Build Setting 里搜索 Preprocessor Macros
,
并给 Debug 添加为 DEV=1
, Test 添加 TEST=1

基本上已经设置完毕了 可以通过 #ifdef
#elif
#else
#endif
愉快的切换环境了
#ifdef DEBUG
#define kLog(s, ... ) NSLog( @"[%@ in line %d] =========>%@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define kLog(s, ... )
#endif
#ifdef DEV
#define kBaseUrl @"http://dev.com"
#elif TEST
#define kBaseUrl @"http://test.com"
#else
#define kBaseUrl @"http://release.com"
#endif