美文网首页
PReprocessor Macros : 全局宏命令的应用

PReprocessor Macros : 全局宏命令的应用

作者: 英雄出少年 | 来源:发表于2018-04-23 18:17 被阅读18次

一、设置全局宏
进入'Build Settings' ->搜索'PreprocessorMacros’然后如图所示进行设置

20161201195653576.png

应用场景
1.debug模式下用测试服务器地址,release模式下用线上服务器。

#if PROD == 1  
// 正式服务器地址  
 NSString * const SERVER_URL = @"http://www.baidu.com/";  
#else  
// 测试服务器地址  
 NSString * const SERVER_URL = @"http://www.google.com/";  
#endif 

2.多个target可以通过全局宏切换

TARGET_VERSION==1.png TARGET_VIERSON==2.png

#if TARGET_VERSION == 1
 NSString *app_name =  @"微信"
#elif TARGET_VERSION == 2
 NSString *app_name = @"支付宝"
#endif

相关文章

网友评论

      本文标题:PReprocessor Macros : 全局宏命令的应用

      本文链接:https://www.haomeiwen.com/subject/kfillftx.html