I'm using the forwardInvocation:
feature of objective-c and I need to know what type of argument the method received. In my example I'm passing it an int
but getArgumentTypeAtIndex:
tells me it's an id
instead. Here's a simple example:
@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
Here's how I call it:
[Do stuff:123];
Any idea why I'm not getting id
instead of int
as the type?