I\'d like to do the following in Xcode:
Find all NSLog commands without comments, and replace it with //NSLog...
In other words, I want to comment all NSLog
Add the following line to your .pch file
#define NSLog
for enable comment it
You can do this in a single find and replace operation. You can just do this simple Regular Expression replace. This handles both the commented(//) and non-commented lines. This also works even if the previous commented lines has more than two forward slashes(like ///)instead of rwo. You can refer this link. Do the following steps.
(/)*(NSLog.*)
in Find field.//\2
in the Replace field.Enjoy the beauty of regular expressions ;-)
try this also:
#define NSLog(@"YOUR MESSAGE HERE!") do { } while (0)
The answers you have are correct for your question. But. Your real question is how to turn of NSLogs in certain conditions. i.e. you want them to show for Debug builds, and not for Release builds. In which case try defining and using the DLog()
macro as described on Cocoa Is My Girlfriend. If you're using Xcode4 it's even easier because the Debug
and Release
builds define and undefine DEBUG
so you don't have to do that.
It's a lot easier than commenting and uncommenting lines of code.
#ifdef RELEASE
#define NSLog(...) do { } while (0)
#endif
is the best way i found so far.
I would do this
#define EnableNSLog 1
#if EnableNSLog == 0
#define NSLog //
#elif EnableNSLog == 1
#warning Disable NSLog
#endif
This should generate a warning message to remind me to disable NSLog
before final release.