• 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:00:28 +0100

Francisco,

On Thursday, Mar 18, 2004, at 07:41 Europe/Prague, Francisco Tolmasky wrote:

When I have a textview, and call [[textview string] substringWithRange: someRange], if I want to save that string, do I need to send it the copy: message, or am I ok with just retaining it (given that the string in the textview will be edited).

presumed you want a snapshot of the moment you called substringWithRange:, *do* use copy! It is possible that in the current implementation it is superfluous (but harmless), but it may change in future.

Generally, *whenever you need a snapshot of the current state, use copy*. Use retain only in case you explicitly want to *share* the object.

There's a mechanism of mutable/immutable objects which ensures it is ver efficient and you don't do any unnecessary copying in fact (unless someone uses mutable objects for immutable data, which, of course, is a design bug).
---
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.


  • Follow-Ups:
    • Re: substring return a new string?
      • From: Marco Scheurer <email@hidden>
References: 
 >substring return a new string? (From: Francisco Tolmasky <email@hidden>)

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