The following code works as expected:
NSLog(@"%@", [NSString stringWithString:@"test"]; // Logs "test"
But when I replace it with an NSInvocation
, I get a totally different result:
Class class = [NSString class];
SEL selector = @selector(stringWithString:);
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[class methodSignatureForSelector:selector]];
[invocation setTarget:class];
[invocation setSelector:selector];
[invocation setArgument:@"test" atIndex:2];
[invocation invoke];
id returnValue = nil;
[invocation getReturnValue:&returnValue];
NSLog(@"%@", returnValue); // Logs "NSCFString"
I've searched high and low, but cannot figure this out. Any help? Thanks!