最近正在做一個(gè)APP,需要獲悉調(diào)用的方法名字,看到了一篇博文,是使用_cmd實(shí)現(xiàn)的
“The _cmd variable is a hidden argument passed to every method that is the current selector”
就是說(shuō)_cmd在Objective-C的方法中表示當(dāng)前方法的selector
比如我們打印要調(diào)用的方法可以這樣寫(xiě):
- (void)viewDidLoad {
[superview DidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"Current method: %@",NSStringFromSelector(_cmd));
}
打印結(jié)果:
Current method: viewDidLoad?