3

I am new to iPhone and trying to learn the sequence of methods invoked during application loading time.

After some googling, I found this that seems to be adequate: NSLog(@"Begin %@ initWithNibName", [[self class]description]); But is there a way to insert the method name instead of typing it myself? Is there even a better TRACE log command???

Also, I found this on the internet:

#define METHOD_LOG (NSLog(@"%@ %s\n%@", \
    NSStringFromSelector(_cmd), __FILE__, self))

But I don't know what it does and how to use it. I tried: -(id) init { METHOD_LOG("init"); ...... }

But doesn't compile.

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
jabawaba
  • 279
  • 1
  • 6
  • 16

1 Answers1

5

I use this to log the current method or function (works for both):

NSLog(@"%s", __FUNCTION__);

To use the macro you quoted, you just type:

METHOD_LOG;
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • Thank you. Your macro is very useful. I've been using it all the time now. Btw, what's the difference between @"%s" and @"%@". I tried googling it but google doesn't understand @ and %s. – jabawaba Nov 26 '10 at 20:41
  • `%@` prints an Objective-C object (such as an `NSString`) and `%s` prints a C-style null-terminated string. See http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html – Ole Begemann Nov 26 '10 at 21:58