On Thu, 15 Sep 2011 10:29:42 -0700, Matt Neuburg <
email@hidden> wrote:
> On Thu, 15 Sep 2011 09:43:00 -0700, Jerry Krinock <
email@hidden> said:
> I'm trying very hard to embrace change and get on board with Xcode 4. The worst thing for me is the loss of User Scripts, in which I had keyboard shortcuts for adding and bulk-removing NSLog() statements in a flash.
> Back in one of those rambling Xcode 4 threads on July 24, Patrick William Walker wrote:
> "The new action triggers inside the debugger are pure freakin' gold. I haven't used NSLog() in weeks now."
> I can't find any documentation on "action triggers". I'd appreciate an explanation of what "action triggers" are, and how they obviate NSLog(). I hope they does not require running with breakpoints on.
> He's talking about a breakpoint that logs and continues. But, as you say, this requires that breakpoints be turned on. In early versions of Xcode 4 this feature was broken (it worked, but the interface claimed we were paused at the breakpoint), but it seems okay now.
> My favorite way to deal with NSLog, stolen from Jens Alfke, is to call MyLog instead, with a definition in the precompiled header like this:
> #define MyLog if(0); else NSLog
> When it's time to stop logging, change the 0 to 1. So elegant. m.
This is what I use in my pre-compiled header:
#ifdef DEBUG
#define NSLogDebug(format, ...) \
NSLog(@"<%s:%d> %s, " format, \
strrchr("/" __FILE__, '/') + 1, __LINE__, __PRETTY_FUNCTION__, ## __VA_ARGS__)
#else
#define NSLogDebug(format, ...)
#endif
Then in the debug configuration define DEBUG:
GCC_PREPROCESSOR_DEFINITIONS = $(value) DEBUG=1
So without changing anything my release builds have all their NSLogDebug's no-op'd out. Plus the format, __VA_ARGS__ allow me to do things like:
- (void) windowWillClose: (NSNotification *) notification {
NSLogDebug(@"id:%@, notification: <%@>", [self uniqueID], notification);
.
.
.
} // windowWillClose:
Which logs:
2011-09-16 09:09:39.727 CSR Progress Meter[39032:707] <ProgressMeter.m:188> -[ProgressMeter windowWillClose:], id:SPM-39032-1, notification: <NSConcreteNotification 0x100345260 {name = NSWindowWillCloseNotification; object = <NSWindow: 0x10014ef90>}>
--
Enjoy,
George Warner, x4-0668
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)
eMail: <
email@hidden>
iChat: <
email@hidden>