Tuesday, September 25, 2012

Force a block of code to only run on release / production

As in, I want to log a bunch of data, but only when I'm running the app on my computer (in Debug or Development mode). From the sounds of it, the preprocessor macro DEBUG is set to 1 automatically for Debug and Development mode so you don't actually have to do anything.


How can I add an #ifdef DEBUG to Xcode?

zoul answered:

In recent Xcode project templates there’s already a DEBUG=1 macro defined for the Debug build configuration (in the Preprocessor Macros section). You can test it using the #if preprocessor directive.

Also check out zoul's comment, he gives you all the info you need:
Ah yes, thanks, the whole build thing is getting… complicated :) I’ve edited the post. @nevan, take a look at Build Settings and filter for “preprocessor”. You should see a section called Preprocessor Macros, that’s where you should put a DEBUG=1 line next to the Debug sch—— configuration.

Basically

#ifdef DEBUG
 //put code here
#endif

if you want to avoid certain code running on the released version of your app

No comments:

Post a Comment