简体   繁体   中英

How can I print the name of the object / interface with Xcode breakpoint log?

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.

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.

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.

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

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

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

This will output, eg [SomeClass someMethod:]

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM