View Full Version : Accessing method return value & Cocoa GI question

Oct 12, 2010, 11:08 PM
First off, just wanted to thank those who helped me in my earlier thread. I got a Cocoa app up and running in pretty short time.

I'm working on a few more bits to the app and I have a question. Is there a way to access the value that gets returned from a method (hopefully I got my terms straight)?

Here's the code I'm working on:
-(float) calcPerformance
if((int)currentTemp % 10 == 0)
return lowAltLowTemp + self.pressureFactor * (highAltLowTemp - lowAltLowTemp);
else if((int)pressureAltitude % 1000 == 0)
return lowAltLowTemp + self.tempFactor * (lowAltHighTemp - lowAltLowTemp);
return (valueTop + self.pressureFactor * (valueBottom - valueTop));

What I want to do is use the value that gets returned for calcPerformance in one more calculation and then display that value again. I think I could work it out by adding another variable and instead of returning the value, just put the value equal to a variable and make it a void method. But it seems like it would be simpler if I could access that value another way.

Also, quick question. I can't find much on tutorials or help on adding a TabView to my interface. I'd like to be able to switch between 3 different interfaces if possible..

Oct 13, 2010, 01:15 PM
What I want to do is use the value that gets returned for calcPerformance in one more calculation and then display that value again.

As a rough guideline, you need to think about whether calcPerformance remains useful as a somewhat stand-alone function -- or whether it needs this "one more calculation" in order to be useful (or indeed correct).

Answering that question will help you decide between:

modifying calcPerformance
a new function that calls calcPerformance and performs the calculation
a new function that performs the calculation on a parameter

Does that make sense?

Oct 13, 2010, 03:10 PM
I think I understand what your getting at.

calcPerformance is definitely useful as a stand-alone function. It's basically the value that your looking to get out of the program.

Here's what this extra calculation is about. calcPerformance calculates your takeoff distance in an airplane without any wind consideration. Now let's say there is a 9 knot headwind. That means I need to take 10% of the calcPerformance value. So I can't do that calculation until I've got a value for calcPerformance.

So yeah.. I would like a new function "windCalc" (or whatever) to call the value from calcPerformance, use it, and return a new value to display.

Oct 14, 2010, 03:51 AM
Sounds good :)

Are you familiar with defining, and calling, functions that take parameters in Objective-C?

Oct 14, 2010, 09:07 PM
Define as in: -(void) method: (int) n;

Like that?

Not too familiar. Pretty new to objective-c.

Oct 15, 2010, 02:42 AM
Yes, that's it; you're on the right track. Good luck :)