您可以通过NSMethodSignature该类获取有关特定选择器的大量信息:
id obj = ...
SEL selector = ...
NSMethodSignature *signature = [obj methodSignatureForSelector:selector];
NSUInteger args = [signature numberOfArguments];
int i;
for(i = 0; i < args; i++)
printf("argument type at index %d: %c", i, [signature getArgumentTypeAtIndex:i]);
Run Code Online (Sandbox Code Playgroud)
您可以使用 进行检查respondsToSelector:,即如下所示:
if ( [myObject respondsToSelector:@selector(doSomethingWithOneArgument:)] ){
....
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
327 次 |
| 最近记录: |