• 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: NSMutableString appendString: "appending self" allowed?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableString appendString: "appending self" allowed?


  • Subject: Re: NSMutableString appendString: "appending self" allowed?
  • From: Martin Wierschin <email@hidden>
  • Date: Thu, 30 Aug 2007 00:07:43 -0700

is the following call allowed?

[someMutableString appendString:someMutableString];

That's an interesting question. From an API point of view it should definitely work and if you find a case where it doesn't then I would report it as a bug. Of course, that doesn't mean whatever concrete string implementation you happen to have was thinking about this situation when it was coded.


[someMutableString appendString:[[someMutableString copy] autorelease]];

or

[someMutableString appendString:[someMutableString subStringToIndex: [someMutableString length]]];

If you're paranoid to the point of not using "appendString" directly, then I would use the first alternative. The substring in the second line might be the same mutable instance since it covers exactly the same characters. I'm actually not sure whether NSMutableString could do that as an optimization, but I don't believe there's any contract that returned substrings are immutable with respect to the source. Always copy if you need to ensure immutability.


~Martin

_______________________________________________

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: 
 >NSMutableString appendString: "appending self" allowed? (From: Manfred Schwind <email@hidden>)

  • Prev by Date: How to create .widgetplugin with java source file??
  • Next by Date: Different methods for setting the delegate?
  • Previous by thread: NSMutableString appendString: "appending self" allowed?
  • Next by thread: Re: NSMutableString appendString: "appending self" allowed?
  • Index(es):
    • Date
    • Thread