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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to