我正在使用 NSInvocation 进行动态调用:
NSInvocation *lNSInvocation = [NSInvocation invocationWithMethodSignature: [lListener methodSignatureForSelector:lSelector]];
[lNSInvocation setTarget:lListener];
[lNSInvocation setSelector:lSelector];
// Note: Indexes 0 and 1 correspond to the implicit arguments self and _cmd, which are set using setTarget and setSelector.
[lNSInvocation setArgument:object atIndex:2];
[lNSInvocation setArgument:object2 atIndex:3];
[lNSInvocation setArgument:object3 atIndex:4];
[lNSInvocation invoke];
在调试器中,所有三个对象变量都正确指向三个不同的 NSCFString*。调用完成,另一方面,到达了正确的方法。
- (void)login:(NSString*)username password:(NSString*)password host:(NSString*)host
但是,在调试器中,它的参数给出错误:“变量不是 CFString”。更糟; 所有三个变量都指向同一个内存位置。
怎么会这样?