How to pass an integer using the performSelectorInBackground function

I do not want to pass an object with an object. Can I only pass it with Int? if not, how can i do this? Thank.

[myController performSelectorInBackground:@selector(passAnInt:) withObject:int];
+3
source share
1 answer

You can insert intin 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 return intagain using the NSNumber method intValue. See the NSNumber link for more details .

+11
source

Source: https://habr.com/ru/post/1762780/


All Articles