Debugging
I'm writing a script that uses several debug statements here and there. The thing is, I only want to have them show up when the symbol DEBUG_MODE is defined.
I have two questions about this:
1. how do I add the DEBUG_MODE symbol to Xcode?
2. If I had a debug statement such as this:
#define LOG_DEBUG(str) NSLog(@"%@", str)
how could I have it only run when the symbol DEBUG_MODE is on?
Thanks in advance.
It's usual to say
#ifdef _DEBUG
#define LOG_DEBUG(str) NSLog(bla bla bla,str);
#else
#define LOG_DEBUG(str)
#endif
So when you don't define _DEBUG, there's nothing left! You'll find however that this is a little restrictive, as you can only pass one argument on your LOG_DEBUG macro. Of course you could add more macros such as LOG_DEBUG2(a,b) - or equally, place the code in-line surrounded by #ifdef _DEBUG ... #endif
Another smart way however is to have a logging class that can be configured from outside the application - so that by default it logs when debugging. This way you can trigger logging in your release build - even although the default for release is not to log. You'll be surprised at how often issues appear in the release build and you say "gosh, I wish I could see the log".
You define _DEBUG as a compiler in your project setting for debug.