简体   繁体   中英

NSInvocation with value type arguments

Is it possible to use NSInvocation with value type arguments?

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.

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.

If I get what are you looking for, you just want to pass an int as first parameter?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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