Archive for February, 2009

Simple “method got called” debugging

Thursday, February 26th, 2009

For quick and dirty project debugging, I often find myself using code like:

- (void)someRandomMethod
{
NSLog(@"-someRandomMethod called");
// ...
}

Playing around with precompiled headers in XCode, it occurred to me there’s a much neater way to do this. In the precompiled header (XCode probably created a .pch file for you) add:

#define HELLO NSLog(@"-----TRACE----- %s (%s:%d)", __PRETTY_FUNTION__, __FILE__, __LINE__);

Then in any method in your project you can get easy tracing:

- (void)someOtherMethod
{
HELLO
// ...
}

To prevent trace messages ever showing up in release builds, you could wrap the definition in an #ifdef and make the macro effectively a no-op.