Accessing method return value & Cocoa GI question

Discussion in 'Mac Programming' started by jakee.stoltz, Oct 12, 2010.

  1. macrumors newbie

    Joined:
    Sep 17, 2010
    #1
    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..
     
  2. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    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?
     
  3. thread starter macrumors newbie

    Joined:
    Sep 17, 2010
    #3
    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.
     
  4. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #4
    Sounds good :)

    Are you familiar with defining, and calling, functions that take parameters in Objective-C?
     
  5. thread starter macrumors newbie

    Joined:
    Sep 17, 2010
    #5
    Define as in: -(void) method: (int) n;

    Like that?

    Not too familiar. Pretty new to objective-c.
     
  6. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #6
    Yes, that's it; you're on the right track. Good luck :)
     

Share This Page