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开发者_如何学C 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 DEBUG
means that, if DEBUG
is 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).
I believe your code block would only check if you are building for debug or release and will build accordingly.
You can build it on a device it will be on release mode , I don't think it is possible to run the simulator in release mode otherwise.
Maybe manually building the application for simulator and moving the packed file to run only on simulator without running xcode, but it will not be reasonable I guess.
精彩评论