0

Xcode debug log can print the method name using %B and the hit count using %H. How can I print the interface / object name using similar notation ? Preferably without the use of NSLog / debugger command.

lalthomas
  • 442
  • 5
  • 14

5 Answers5

1

The closest you can get is

NSLog("My file is %@", [NSString stringWithUTF8String:__FILE__]);

__PRETTY_FUNCTION__ contains the class name and method, which may suit you better than FILE.

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
  • I was expecting an answer without using NSLog. – lalthomas Apr 21 '15 at 12:45
  • OK Well if not NSLog, how do you want it? You could use the same parameters and call printf instead, for example. – Graham Perks Apr 21 '15 at 15:29
  • Like the one which doesn't need a debugger action but a only a log action. See [my answer](http://stackoverflow.com/a/29774554/2182047). Do you have any similar answer ? – lalthomas Apr 21 '15 at 19:45
1

I just found that @[self class]@ log message will do the trick. I am not sure its validity on every occasion. I am using @[self class]@ %B %H for my purpose. I also found this question and answer but it was not just working on Xcode 6.2.

Community
  • 1
  • 1
lalthomas
  • 442
  • 5
  • 14
0

Every Objective-C object can be printed with %@. NSLog(@"%@", someObject) will print object's description. You can override description method for your classes to provide more detailed info. Look at this note too: Improved logging in Objective-C

Vlad
  • 7,199
  • 2
  • 25
  • 32
0

In the breakpoint's debugger command action, you can put:

expr printf ("[%s %s]\n", (char *)object_getClassName(self), _cmd)

This will output, e.g. [SomeClass someMethod:]

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
-1

You can print anything using NSLog();

Say, for example, you have an

NSString *myString = @"qdfsqsdfqsdf";

This is an important string you would like to log, you'll just type :

NSLog(@"My important string : %@", myString);

If that is what you're asking, I'm surprised you dont' know that if you already know about %B & %H. Am I answering your question or do you need a bit more?

Gil Sand
  • 5,802
  • 5
  • 36
  • 78