views:

152

answers:

2

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?

+2  A: 
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.

MiRAGe
+3  A: 

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]);
jrbj