• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Returning a value from a function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning a value from a function


  • Subject: Re: Returning a value from a function
  • From: Mike Abdullah <email@hidden>
  • Date: Tue, 8 Apr 2008 09:43:52 +0100


On 8 Apr 2008, at 09:37, Bryan Henry wrote:

Change your function definition to - (NSString*)convertFunctionWithValues:(NSString*)....etc and just add "return retVal;"

Also, its not really necessary but in the interest of good coding practices you may want to consider passing an array (NSArray of NSNumber or whatever) to -[convertValues convertFunctionWithValues:ValueTwo:ValueThree:ValueFour:ValueFire:ValueSix:ValueSeven:ValueEight:Pecision :] since as I'm sure you can tell that's quite the doozy of a function name.

You also don't need the = @"" part from your NSString declaration.

Bryan

On Apr 7, 2008, at 4:59 PM, Stuart Green wrote:

Hi,

I've currently got a function of type void that works swimmingly in the debugger. I now need to populate a text field with the value of the generated string within the function. The function is declared along the lines:

- (void)convertFunctionWithValues:(NSString *)valueOne ValueTwo: (double)valueTwo ValueThree:(double)valueThree ValueFour: (double)valueFour ValueFive:(NSString *)valueFive ValueSix: (double)valueSix ValueSeven:(double)valueSeven ValueEight: (double)valueEight Precision:(int)precision;
{
// Declarations here
NSString *retVal = @"";


// Calculations go here...
// Lots of them...

// We've got the result, now we want to return it
retVal = [NSString stringWithFormat:@"%c%c%i%i", retLet1, retLet2,retFinalCalcA,retFinalCalcB];


}

How do I now return this string value? The initialisation and calling is done via:

convertedValue = [[convertValues alloc] init];
valToBeDisplayed = [convertedValue convertFunctionWithValues:valueOne ValueTwo:valueTwo ValueThree:valueThree ValueFour:valueFour ValueFive:valueFive ValueSix:valueSix ValueSeven:valueSeven ValueEight:valueEight Precision:precision];
// Display returned value
self.valDisplayField.text = valToBeDisplayed;
[convertedValue release];

Also, according to your code at the bottom here, you want to return a value from a METHOD not a function.


Mike.


Any ideas appreciated.

Thanks,

Stu


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Returning a value from a function
      • From: Bryan Henry <email@hidden>
References: 
 >Returning a value from a function (From: Stuart Green <email@hidden>)
 >Re: Returning a value from a function (From: Bryan Henry <email@hidden>)

  • Prev by Date: Re: Returning a value from a function
  • Next by Date: Re: Returning a value from a function
  • Previous by thread: Re: Returning a value from a function
  • Next by thread: Re: Returning a value from a function
  • Index(es):
    • Date
    • Thread