Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jiminaus

macrumors 65816
Original poster
Dec 16, 2010
1,449
1
Sydney
Hi all,

I've been browsing through a few Cocoa projects to see how other people do it.

I see a lot of a code like the following when using NSLog.

Code:
NSLog(@"%@", NSStringFromSelector(_cmd));

What's the advantage of that over what I use which is.

Code:
NSLog(@"%s", __PRETTY_FUNCTION__);

I was taught the former but started using the later because the output includes the full method declaration, and importantly for me includes the class where the method was defined. The former just outputs the message name.
 
The one main advantage I can see is __PRETTY_FUNCTION__ is part of GCC so it can be used in C and C++ as well, allowing it to be used more generically if you were mixing languages and wanted all of them to use the same logging macro.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.