Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mettra

macrumors newbie
Original poster
Mar 24, 2009
9
0
I am currently making an application for fun, and I was wondering how to make a check to see if a variable (or variables) have reached a certain value.

I believe I need to do something with the (void) tag, however I am not sure what...

Any help is appreciated.
 
no, not for an if tag. I need some statement running in the background to be constantly checking if a variable equals a number.

Example: The user presses a button, and variable foo increases by 1. Once foo equals 5 a message displays saying "YAY!" or something. ;)
 
no, not for an if tag. I need some statement running in the background to be constantly checking if a variable equals a number.

Example: The user presses a button, and variable foo increases by 1. Once foo equals 5 a message displays saying "YAY!" or something. ;)
Why run the check in the background? Why not just check it when the button is pressed?

variable == "whatever string"
Besides, that's not how you check a string for equality. You probably wanna use NSString's isEqualToString: instance method.
 
do you want something like this
Code:
- (IBAction)buttonPressed:(id)sender
{
int foo = 0;
while (foo < 5)
foo++;

this will increment foo from 0 to 5, and inside the while loop you can do more computation if thats required.

or:
Code:
for (int i=0; i< 5; i++)
{
// do what ever you need to do 5 times
}
 
If you want to make it fancy, use a setter for all the variable assignments, and then use notification handlers for all the objects that need to watch the variable.
 
do you want something like this
Code:
- (IBAction)buttonPressed:(id)sender
{
int foo = 0;
while (foo < 5)
foo++;

this will increment foo from 0 to 5, and inside the while loop you can do more computation if thats required.

or:
Code:
for (int i=0; i< 5; i++)
{
// do what ever you need to do 5 times
}
I believe the OP wants something whereby each time the button is pressed, the variable is incremented. In that case, the variable will have to be instantiated and initialized outside of the button-press code.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.