Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a integer using performSelectorInBackground

I don't want to passAnInt with object. Can I pass it with Int only? if not , how can I do so? Thank you.

[myController performSelectorInBackground:@selector(passAnInt:) withObject:int];
like image 419
DNB5brims Avatar asked Nov 21 '25 16:11

DNB5brims


1 Answers

You can box the int within an NSNumber. If your method signature is:

- (void)passAnInt:(NSNumber *)someNumber;

Then you can call it using:

int someInt = 5;
NSNumber *num = [NSNumber numberWithInt:someInt];
[myController performSelectorInBackground:@selector(passAnInt:) withObject:num];

Then, in your method, you can get the int back out again using NSNumber's intValue method. See the NSNumber class reference for more.

like image 158
Tim Avatar answered Nov 24 '25 23:11

Tim