Re: A quick one: Passing a reference/pointer to NSString
Re: A quick one: Passing a reference/pointer to NSString
- Subject: Re: A quick one: Passing a reference/pointer to NSString
- From: Graham Cox <email@hidden>
- Date: Wed, 23 Jul 2008 11:41:12 +1000
NSString is not mutable, so once created, you can't change its
contents. You can reassign the pointer to another string, as you are
doing - though without knowing your intentions it doesn't really look
right (and could cause a memory leak). Your 'foo' method is prototyped
to return a string but isn't doing that, so maybe that's why you're
not seeing what you expect?
What are you trying to do? If you want to change the content of a
string, you could use NSMutableString, but the code you've posted
isn't a great pattern for string manipulation so the intention of it
isn't clear (to me, anyway).
cheers, Graham
On 23 Jul 2008, at 11:33 am, Jeff Brown wrote:
Hi Guys
What do I need to do in the following code to get theString to take
the value I'm giving it in foo i.e. "Hi there"?
- (void) aMethod
{
NSString* theString = @"";
[self foo:theString];
}
- (NSString*) foo:(NSString*)aString
{
NSString* stringB = @"Hi there";
aString = stringB;
}
Thanks guys.
_______________________________________________
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