【Tip】利用Xcode的环境变量来控制特定的代码开关
通常的做法是在启动时设置一些变量
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //... #if DEBUG NSFNetworkLayerLogging = YES; NSFModelLayerLogging = YES; //... #endif return YES; }
多人协作时,一个人调试时打开的开关,很可能会混在正常的修改里一起提交到仓库中,影响到其他人的配置。
解决方案
将开关移到Xcode的Environment variables设置里
然后
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //... #if DEBUG NSString *string = [[NSProcessInfo processInfo] environment][@"NSFModelLayerLogging"]; NSFModelLayerLogging = [string boolValue]; #endif return YES; }