1

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.

Gaurav Sharma
  • 2,680
  • 3
  • 26
  • 36
  • 3
    That's how you do it, where `param1` is an integer or whatever primitive datatype you want. The graphical debugger is sometimes wrong, and note especially if you're using a breakpoint that it won't show the value of an assignment until _after_ the line containing the assignment. – jscs Nov 10 '14 at 19:38

1 Answers1

3

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.

tbaranes
  • 3,560
  • 1
  • 23
  • 31