我正在使用forwardInvocation:
objective-c 的功能,我需要知道该方法收到的参数类型。在我的示例中,我传递了它,int
但getArgumentTypeAtIndex:
告诉我它是一个id
。这是一个简单的例子:
@interface Do : NSObject
+ (void) stuff:(int)x;
@end
@implementation Do
+ (NSMethodSignature *) methodSignatureForSelector:(SEL)selector
{
NSMethodSignature* signature = [super methodSignatureForSelector:selector];
if (!signature)
signature = [self methodSignatureForSelector:@selector(forwardInvocation:)];
return signature;
}
+ (void)forwardInvocation:(NSInvocation *)i
{
const char* argType = [i.methodSignature getArgumentTypeAtIndex:2];
NSLog(@"%s == %s", argType, @encode(id)); // @ == @
NSLog(@"%s == %s", argType, @encode(int)); // @ == i
}
@end
我是这样称呼它的:
[Do stuff:123];
知道为什么我没有得到id
而不是int
作为类型吗?