I guess it's really simple, but I can't find the way to work this out...
@property (strong, nonatomic) NSMutableArray *randomQuestionNumberArray;
I have a method beginning like this
- (int)showQuestionMethod:(int)number;
In this method I have a loop where I fill NSMutableArray
with numbers and then shuffle it.
//Creating random questions array
_randomQuestionNumberArray = [[NSMutableArray alloc] init];
for (int i = 0; i < numberOfQuestions; i++) {
[_randomQuestionNumberArray addObject:[NSNumber numberWithInt:i]];
}
//Shuffling the array
NSUInteger count = [_randomQuestionNumberArray count];
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
int nElements = count - i;
int n = (arc4random() % nElements) + i;
[_randomQuestionNumberArray exchangeObjectAtIndex:i withObjectAtIndex:n];
}
And this works pretty well. Let's say it shuffles the numbers like 4, 5, 1, 3, 6, 0, 2.
Now in viewDidLoad I try to call the the method showQuestionMethod
with the first value of _randomQuestionNumberArray
which should be 4 in this case.
[self showQuestionMethod:[_randomQuestionNumberArray[0] intValue]];
The problem is that the method gets passed the value of 0 all the time when it should be 4, but NSLog(@"first value is %@", _randomQuestionNumberArray[0])
returns the correct value of 4.
How do I get around this and convert id type to int?