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

jakee.stoltz

macrumors newbie
Original poster
Sep 17, 2010
17
0
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:
Code:
-(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);
	}
	else
	{
		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..
 

ianray

macrumors 6502
Jun 22, 2010
452
0
@
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:
  1. modifying calcPerformance
  2. a new function that calls calcPerformance and performs the calculation
  3. a new function that performs the calculation on a parameter

Does that make sense?
 

jakee.stoltz

macrumors newbie
Original poster
Sep 17, 2010
17
0
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.
 

ianray

macrumors 6502
Jun 22, 2010
452
0
@
Sounds good :)

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

jakee.stoltz

macrumors newbie
Original poster
Sep 17, 2010
17
0
Define as in: -(void) method: (int) n;

Like that?

Not too familiar. Pretty new to objective-c.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.