Re: NSMutableString appendString: "appending self" allowed?
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