Quote:
Originally Posted by canit210
thanks that's exactly what i was looking for.
Would that go in the .m file or the .h file?
Depending on which one, would I need to add anything to the other one. (I'm a beginning programmer so please be nice!)
Thank you.
|
You need to declare variables in the .h file if they're used in more than one method, and you want them to keep their value. They're called instance variables.
Code:
//these would go between the interface brackets
int weightedRandom;
NSString *mathQuestion; //I forgot the asterisk last time
Any code that performs an action (as opposed to just declaring variables) goes in the .m file. If you've already declared the variables in the .h file, then the code changes a little. We don't need to declare the variables again, we can just use them:
Code:
int randomA = arc4random() % 6;
int randomB = arc4random() % 6;
weightedRandom = randomA + randomB;
int randomA = arc4random() % 6;
int randomB = arc4random() % 6;
mathQuestion = [NSString stringWithFormat: @"%d + %d", randomA, randomB];