• 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 value in a function argument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: returning value in a function argument


  • Subject: Re: returning value in a function argument
  • From: Prachi Gauriar <email@hidden>
  • Date: Wed, 17 May 2006 21:53:52 -0400


On May 17, 2006, at 8:09 PM, Angelo Chen wrote:

How to return NSString in a function argument?

The other replies seem a bit too specific to NSStrings. The typical way to do this for any type in C is as follows:


void getInfo(NSString **info)
{
    if (!info) return;
    *info = @"my info";
}

It's called like:

NSString *info = nil;
getInfo(&info);

Note that the info parameter is declared as an NSString **, not an NSString *. This is called returning a value "indirectly." The same technique is used to return NSErrors throughout Cocoa in Tiger. It's also used by NSStream's +getStreamsToHost:port:inputStream:outputStream, and probably a number of other methods.

Remember to follow memory management rules. There was a thread about this recently.

-Prachi
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >returning value in a function argument (From: Angelo Chen <email@hidden>)

  • Prev by Date: Re: restoring the stored scroll position of an NSTableView and it's NSTableHeaderView.
  • Next by Date: Re: drawKnob in NSSliderCell subclass
  • Previous by thread: Re: returning value in a function argument
  • Next by thread: Making newly inserted row visible in NSTableView
  • Index(es):
    • Date
    • Thread