I’m having some trouble passing a number as an argument for a method:
- (void)meth2:(int)next_int;
And to call that method I need this:
int next_int = 1;
[self performSelectorOnMainThread:@selector(meth2:) withObject:next_int waitUntilDone:NO];
//update next_int and call meth2 again
at this point, I get a “pointer from integer without a cast” error and would happen the same with a NSInteger. An NSNumber is not useful because it’s immutable and I need to change the value constantly.
Any idea how can I do this?
Thanks.
If you’re just trying to call the method, you could use the standard syntax:
If you really need to use the
performSelectorOnMainThread:you could wrap the number in anNSNumberfor the call. You say you can’t do this because you need to change the number, but you can just pull an int out and change that:But maybe you mean that you want to get the value of the number as an output from your call to
meth2. If that’s what you mean, then you could pass in a double pointer so you can receive a new object back:Of course, that’s not really thread-safe, so if you’re doing stuff with multiple threads, I would advise using the
@synchronizedkeyword for access to multi-thread-accessed variables, or setting up atomic properties (i.e. properties not declared asnonatomic).Also, meth is bad for you!! haha