Re: returning value in a function argument
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