Reputation:
I need the name of the class that owns a method, as NSString
. Example: There's a -fooBar
method inside a SomeClass
, and that -fooBar
method runs some code. This code must print out what class "owns" it, I mean: What class that method belongs to. So I can't hard-type the class name in a NSString
because I need that for debugging purposes, determining dynamically the name of the class. Hard to explain. Any idea?
Upvotes: 29
Views: 18933
Reputation: 3973
NSLog(@"%@",[self className]);
Update: sorry, I didn't realize className didn't exist on the iPhone. As the above comment suggested; use ..
NSLog(@"%@", NSStringFromClass([self class]));
.. instead.
Upvotes: 10
Reputation: 731
On the Mac, you can use:
NSString *className = [self className];
or
NSString *className = NSStringFromClass([self class]);
On the iPhone, [self className]
doesn't exist so you'll have to use:
NSString *className = NSStringFromClass([self class]);
Upvotes: 64