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

iOS 获取当前方法的方法名

作者: 达_Ambition | 来源:发表于2018-12-03 22:36 被阅读20次

最近正在做一个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/sxfpcqtx.html