美文网首页
IOS 获取当前方法的方法名

IOS 获取当前方法的方法名

作者: sunny冲哥 | 来源:发表于2017-06-07 14:24 被阅读978次

最近正在做一个APP,需要获悉调用的方法名字,看到了一篇博文,是使用_cmd实现的

“The _cmd variable is a hidden argument passed to every method that is the current selector”

就是说_cmd在Objective-C的方法中表示当前方法的selector

比如我们打印要调用的方法可以这样写:

- (void)viewDidLoad {

[superview DidLoad];

// Do any additional setup after loading the view, typically from a nib.

NSLog(@"Current method: %@",NSStringFromSelector(_cmd));

}

打印结果:

Current method: viewDidLoad 

相关文章

网友评论

      本文标题: IOS 获取当前方法的方法名

      本文链接:https://www.haomeiwen.com/subject/jnoofxtx.html