我的程序中有多个对象,其中一些将方法 A 实现为类方法 ( + (void)A
),而另一些将其实现为成员函数 ( - (void) A
)。如何respondToSelector:
确定给定对象是否支持 A 作为类与对象?
只是要清楚; 我没有实例,我只有使用 [NSBundle classNames:name] 获得的类。现在,我想知道我是否可以简单地A
在类上调用方法,或者我需要先实例化类,然后再调用A
实例。
if ([[NSBundle classNamed:name] respondsToSelector:@selector(A)]){
//Your class responds to the selector i.e. its a class method
} else if ([[NSBundle classNamed:name] instancesRespondToSelector:@selector(A)]){
//Your class' instances respond to the selector, i.e. its an instance method
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句