NS调用;变量不是 CFString
我正在使用 NSInspiration 进行动态调用:
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”。更糟糕的是;所有三个变量都指向同一内存位置。
怎么会这样呢?
I'm making a dynamic call using 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];
In the debugger all three object variables correctly point to three different NSCFString*. The invocation is done and on the other side the correct method is reached.
- (void)login:(NSString*)username password:(NSString*)password host:(NSString*)host
However, in the debugger its parameters give an error: "variable is not a CFString". Even worse; all three variables point to the same memory location.
How can this be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果方法参数是对象,则
-setArgument:atIndex:
需要一个指向可从中复制对象的变量的指针。因此,如果你的字符串是:那么你应该写:(
注意每个对象参数之前的&符号)
If the method arguments are objects,
-setArgument:atIndex:
expects a pointer to the variable from which the object can be copied. Consequently, if your strings are:then you should write:
(note the ampersand before each object argument)