Int or NSInteger as object for method argument. Objective-C

前端 未结 4 990
独厮守ぢ
独厮守ぢ 2021-02-07 14:21

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:

<
4条回答
  •  隐瞒了意图╮
    2021-02-07 14:54

    Wrap the integer in an NSNumber before passing it:

    int next_int = 1
    NSNumber *theNumber = [NSNumber numberWithInt:next_int];
    [self performSelectorOnMainThread:@selector(meth2:) withObject:theNumber waitUntilDone:NO];
    

    Then your -meth2: method could look something like this:

    - (void)meth2:(NSNumber*)theNumber
    {
        int next_int = [theNumber intValue];
        // do whatever
    }
    

提交回复
热议问题