对象内省:方法如何引用其自己的选择器? [英] Obj-C introspection: How can a method reference its own selector?
本文介绍了对象内省:方法如何引用其自己的选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望编写一个可在任何方法中使用的宏,该宏引用该方法的选择器.我不希望传递该方法的字面名称.例如:
I wish to write a macro, to be used within any method, which references the method's selector. I do not wish to pass the literal name of the method. For example:
#define RERUN [self performSelector:{something} withObject:nil afterDelay: 0.0]
其中上面的"{something}"将解析为使用该宏的任何方法的选择器.
where the "{something}" in the above would resolve to the selector of whatever method the macro was used in.
有什么方法可以做到这一点?
Is there some way to do this?
推荐答案
_cmd
表示当前方法的选择器-它是一个隐藏参数(如self
).
_cmd
represents the selector of the current method -- it is a hidden argument (like self
).
如果您永远不需要参数,或者nil
适合您的目的-您所需要做的就是编写:
if you never need arguments, or nil
is suitable for your purpose - all you need to do is write:
#define RERUN [self performSelector:_cmd]
这篇关于对象内省:方法如何引用其自己的选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文