Re: substring return a new string?
Re: substring return a new string?
- Subject: Re: substring return a new string?
- From: Ondra Cada <email@hidden>
- Date: Thu, 18 Mar 2004 12:04:26 +0100
joar,
On Thursday, Mar 18, 2004, at 09:00 Europe/Prague, j o a r wrote:
"substringWithRange:" will create a new string, so you should be able
to simply retain it.
Should be able, of course, but should *NOT* in practice.
It's good that you ask though. I was just recently bitten by this
potential problem - using the string from a text view without a copy
(or other similar way to create a new string).
This is the very reason to never ever retain anything which is not
explicitly meant to be shared. People don't use copy for some strange
reason, and that's bad: in all the situations you want a snapshot of
the current state (which is very often), copy is your best friend.
Namely, practically all the accessors of kind
-(void)setName:, -(void)setPath:, -(void)setTag:, -(void)setFilename:,
-(void)setIdentifier:...
should be implemented with copy instead of retain!
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.