_cmd在Objective-C中的含义

我们知道self表示当前类的一个实例。可以调用方法,访问属性。

那么_cmd是什么呢?

Apple官方文档是这么说的。

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

翻译: _cmd 参数是一个隐藏参数 ,用来传递当前的selector(方法);

 

 

验证一下:

假设我们有一个类叫MyObject  有一个Share方法

+(void)share{

 NSLog(@"Current method: %@ %@",[self class],NSStringFromSelector(_cmd));

}

打印结果为 MyObject share

 

posted @ 2014-11-27 11:53  Shdow_Walker  阅读(324)  评论(0编辑  收藏  举报