I am trying to find a way to prevent user from even compiling the code based on value of some user-defined build setting such as DEBUG=1
. First thing that popped out in my mind is to write a macro something like this;
#if DEBUG=1
#define NS_UNAVAILABLE_IN_PROD NSLog(x);
#else
#define NS_UNAVAILABLE_IN_PROD
#endif
so I am able use it like this;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NS_UNAVAILABLE_IN_PROD
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor blackColor];
}
When I try to compile the code, I get the error:
Use of undeclared identifier 'x'
which is expected, but in some cases, depending on the place where I put this check, a local variable x may be initialized before that so it passes without any error. Thus, I need a more clever way to inform user that the code can't be compiled because he is in DEBUG mode.