iOS: optional code fragments for debug builds

Jakob picture Jakob · Jan 31, 2012 · Viewed 13.9k times · Source

for my App I'd like to have a debug view that I want to have only in debug-builds and not in release builds. I don't want to change my code though. Thats why i am wondering if I can check some compiler flag if this is a release build and exclude some code that i only want to have for debug builds.

Answer

Dan F picture Dan F · Jan 31, 2012

In your projects build settings, look for the preprocessor defines section, in there you can define a variable in your debug build only, such as DEBUG=1, and then use this in your code:

#if DEBUG
    NSLog(@"This will only print in debug!");
#endif

Just make sure in your release configuration, that same define is set to 0 in the same location in your build settings