As a newer programmer, I've discovered the magic of NSlog
, and use it all through my code. It's been extremely helpful (along with NSZombieEnabled
) in debugging.
I can see a definite performance hit on the simulator as it prints out all this stuff. I don't think I see any such hit on devices, but I'm not sure.
So does it cost anything to leave all the NSLogs
in? Is it using more memory on the device? Or does the compiler just ignore them, like it does comments when I compile for a device?
EDIT:
Here's what I implemented, per the suggestion from rano.
In my App_Prefix.pch
file, I added:
// DLog is almost a drop-in replacement for NSLog
// DLog();
// DLog(@"here");
// DLog(@"value: %d", x);
// Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable);
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
And then in my Project Info
inspector, for the Debug
configuration, under the heading GCC 4.2 - Preprocessing,
I added the value DEBUG
to the top entry called, Preprocessor Macros.
Works like a charm - DLog
outputs when I build a Debug
version and ALog
always outputs.