been researching this a while and not sure entirely what to do.
I want to allow users to switch debug mode either on or off. With debug mode on NSLogs will be printed to console.
currently I can set debug mode on or off in the build settings using a preprocessor (DEBUG) and I use the following code to “block” NSLogs.
#ifdef DEBUG
NSLog(@"If you can see this then debug is on");
#endif
I have created a toggle switch in the settings page to get input from the user but I don’t know how to use this input to then undefined/redefine DEBUG. Any ideas?
I am not sure if this is even possible so any alternate solutions would also be appreciated.
Many Thanks 🙂
You should not use preprocessor directives: using
#ifdef DEBUGmeans that, ifDEBUGis not defined, that piece of code doesn’t get compiled at all.You should instead replace preprocessor directives with a simple if statement that check a global variable (or, at least, that may be a solution).