开发者

How to pass a integer using performSelectorInBackground

开发者 https://www.devze.com 2023-01-15 00:18 出处:网络
I don\'t want to passAnInt with object. Can I pass it with Int only? if not , how can I do so? Thank开发者_如何转开发 you.

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];


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消