ajay
ajay

Reputation: 3345

how to display method name and the class name in gdb

Hi all i am working on new app from the beginning.upto now i am using nslog function call to display the output on the gdb.but from the some samples providing me the gdb display with the class and method names.i posted some screenshot for that.can any one guide me to take method name and display name while using nslog().

getting class name and method name with the log

please provide me some information.Thanks in advance.

Upvotes: 4

Views: 4779

Answers (3)

Nishant
Nishant

Reputation: 12617

this will easily print whatever method it is put in...

NSLog(@"%s", __PRETTY_FUNCTION__);

Upvotes: 1

NSGod
NSGod

Reputation: 22948

I use the following:

NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd));

This will dynamically generate both the class name and method name similar to __func__. If you're using Xcode 3.x, what I did was map Command-Option-L to the following user script that inserts a standard logging call like above:

enter image description here

Upvotes: 2

Wevah
Wevah

Reputation: 28242

NSLog(@"the method is %s", __func__);

__func__ is a builtin macro that expands to the current function or class+method name (it's a standard C string, hence the %s formatter instead of %@).

Upvotes: 10

Related Questions