I have a base class called BaseClass . Many classes derived from the BaseClass namely SubClass1 , SubClass2 and SubClass3.
@interface BaseClass: NSObject{
}
-(void)configure;
@end;
@implementation
-(void)configure{
NSLog(@"This needs to log from which sub class this method was called");
}
@end;
The configure method can be called by creating instances of the subclasses or within the implementations of them.
I need to know from which subclass this method was called.
Is this possible?
No. Methods have no way of knowing from which other object’s method they are being called. There’s not even the concept of a caller’s identity. Methods can be called from a C function where there is no caller object at all.
That being said, you probably just want to know of which (derived) class an object is:
2014 Addendum: There’s a gnu extension
__builtin_return_addressthat might be used for this purpose. Mike Ash shows how to use it to extract a callers symbol name (see “Caller Inspection”). I still think that the whole approach is a bit fragile and should only be used for debugging.