Blog Archives

Objective-C Quickie – Printing the name of a method

Getting the name of a method as a string is quite easy in objective-c.  This quickie is useful for logging, or in my case raising an exception if the method is not overridden by a subclass:

NSString *methodName = NSStringFromSelector(_cmd);

NSStringFromSelector is pretty straightforward, and _cmd is one of the two hidden parameters to every objective-c selector (along with self).