• 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: substring return a new string?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Re: substring return a new string? (From: j o a r <email@hidden>)

  • Prev by Date: Re: substring return a new string?
  • Next by Date: Re: substring return a new string?
  • Previous by thread: Re: substring return a new string?
  • Next by thread: Re: substring return a new string?
  • Index(es):
    • Date
    • Thread