• 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: A quick one: Passing a reference/pointer to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >A quick one: Passing a reference/pointer to NSString (From: Jeff Brown <email@hidden>)

  • Prev by Date: A quick one: Passing a reference/pointer to NSString
  • Next by Date: Re: A quick one: Passing a reference/pointer to NSString
  • Previous by thread: A quick one: Passing a reference/pointer to NSString
  • Next by thread: Re: A quick one: Passing a reference/pointer to NSString
  • Index(es):
    • Date
    • Thread