次のコードは期待どおりに機能します。
NSLog(@"%@", [NSString stringWithString:@"test"]; // Logs "test"
しかし、それを に置き換えるとNSInvocation
、まったく異なる結果が得られます。
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"
高低を検索しましたが、これを理解できません。何か助けはありますか?ありがとう!