Friday, December 12, 2008

NSLog with the current selector, __LINE__, __FILE__

This is a handy bit of code I sprinkle in as a quick debug printf:

Just put it in wherever you want to see that your code executed:

3 comments:

Mark Hughes said...

__PRETTY_FUNCTION__ does that. I have this in my Prefix.pch:

#ifdef DEBUG
// DLOG takes a format argument (which must begin %s) and 0 or more args:
// DLOG(@"%s");
// DLOG(@"%s: %d", x);
#define DLOG(fmt, ...) NSLog(fmt, __PRETTY_FUNCTION__, ##__VA_ARGS__)
#else
#define DLOG(...)
#endif

JM said...

Thanks for the tip, Mark. I hadn't known about __PRETTY_FUNCTION__.

Plagiarism detection said...

If you're to lazy to write __PRETTY_FUNCTION__. You can just write __func__. It does the same. http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Function-Names.html