in objective-c can I access the calling classname/methodname within a method?
Background:
I am currently putting the following line in some of my methods for logging:
NSLog(@"<%@:%@:%d>", NSStringFromClass([self class]), NSStringFromSelector(_cmd), __LINE__);
It would be nice to also include the class name and method name(location) of the code that called the method.
Is this possible? What would the code be for this?
thanks
There's no practical way to do this (hence all the methods in Cocoa with sender
arguments). There isn't even a guarantee that there is such a thing — it could be called from a plain old, self
-less function, or it could have been called from a method that was inlined into its calling method, or we could have got to that line from a jump, or….