简体   繁体   English

带值类型参数的NSInvocation

[英]NSInvocation with value type arguments

Is it possible to use NSInvocation with value type arguments? 是否可以将NSInvocation与值类型参数一起使用?

Currently we can do this: 目前,我们可以执行以下操作:

[invocation setArgument:&param1 atIndex:2];

But we'd like that first parameter to be a value type such as int. 但是我们希望第一个参数是一个值类型,例如int。

When I look at the variable being passed to the target method in the debbugger it's some junk value like 1.367481856920029E+302 - which seems like it's converting an object's address to an int. 当我查看在调试器中传递给目标方法的变量时,它是一些垃圾值,如1.367481856920029E + 302-似乎是将对象的地址转换为int。

If I get what are you looking for, you just want to pass an int as first parameter? 如果我得到您想要的东西,您只想将int作为第一个参数传递?

The solution of this issue should be: 该问题的解决方案应该是:

NSInteger param1 = 2;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation setArgument:&param1 atIndex:2];

If it's not answering to your question, please add more details/code. 如果未回答您的问题,请添加更多详细信息/代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM