Just a quick newbie question here. I have a method that calculates a value and stores the result in a double variable, this variable is also a local variable to that method.I also have a second method that does a separate calculation but this method needs the result in the first. How can I get the value from the first method while still keeping that variable hidden to the rest of the class? Below is an example of what I'm trying to get at.
-(IBAction)methodA{
double answer;
answer = 2 + 3;
}
-(IBAction)methodB{
double answerTimeTwo;
answerTimeTwo = answer * 2; //Problem arises here as I cannot access "answer"
}
They shouldn't be decorated as actions unless they're the result of a UIControl event.
Do it like this:
- (double)methodA {
double answer = 2.0 + 3.0; // don't really need the stack variable, but it's okay
return answer;
}
- (double)methodB {
double answerTimesTwo = [self methodA] * 2.0;
return answerTimesTwo;
}