mardi 17 février 2015

Selection a bool through randomizer

I have a total of 6 booleans and the only thing separating them is a number. They're named checker0 though 5.


So checker0, checker1, checker2, checker3, checker4 and checker5.


All of these grants or denies access to certain parts of the app wether the bool is true or false.


I then have a randomiser using:



randomQuestionNumber = arc4random_uniform(5);


So say we get number 3, checker3 = true;


But my question now is would it be possible to set this one to true without having to go thru if statements.


My idea was to implement the way you print a int to say the NSLog using the %d.



NSLog(@"The number is: %d", randomQuestionNumber);


So something like:



checker%d, randomQuestionNumber = true.


Would something like that be possible? So i won't have to do like this:



if (randomQuestionNumber == 0) {
checker0 = true;
}

else if (randomQuestionNumber == 1)
{
checker1 = true;
}


Thanks you very much! :)


Aucun commentaire:

Enregistrer un commentaire