简体   繁体   中英

Incompatible pointer to integer conversion sending 'id' to parameter of type 'int'

I guess it's really simple but I can't find the way to work this out...

I have a method like this

- (int)showQuestionMethod:(int)number;

I'm creating NSMutableOrderedSet in loop like this which works fine.

while (count < numberOfQuestionsInTest) {
    randomQuestionNumber = 0 + arc4random() % (numberOfQuestions - 0);
    [_randomQuestionNumberArray addObject:[NSDecimalNumber numberWithInt:randomQuestionNumber]];
     count = [_randomQuestionNumberArray count];
}

Then when I want to call a method with this line and I get an error (Incompatible pointer to integer conversion sending 'id' to parameter of type 'int')

int showQuestion = 0;
[self showQuestionMethod:_randomQuestionNumberArray[showQuestion]];

Can anyone offer solution? Thank you!

Your _randomQuestionNumberArray contains NSDecimalNumber instances. But your method takes and int parameter. You need to properly convert them:

[self showQuestionMethod:[_randomQuestionNumberArray[showQuestion] intValue]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM