• 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: NSDate Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDate Question


  • Subject: Re: NSDate Question
  • From: Alastair Houghton <email@hidden>
  • Date: Fri, 8 Dec 2006 17:48:45 +0000

On 8 Dec 2006, at 17:26, Sean McBride wrote:

On 2006-12-08 09:19, Roland Torres said:

Noob question here.
Is doing:
  myDate = [aMyDate copy];
preferable to doing:
  myDate = [aMyDate retain];

This could become a long discussion... You might want to google 'accessor patterns'.

But ask yourself: "Do I want the value, or the actual object?" For the
former use 'copy' for the latter use 'retain'. I would think with a
date, it's the value that's more interesting.

Sean's quite right. You should -copy if you want the value and - retain if you want the object.


It makes a difference when people give your method mutable objects; using -retain rather than -copy can be a mistake in that case, because you might end up with an object whose value subsequently changes.

(I'm not sure I'm 100% consistent with this myself, but usually it's *my* code that's calling the methods so I know whether or not I'm giving my methods mutable objects. If you're writing library code for others to use, it's arguably more important.)

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >NSDate Question (From: Matt <email@hidden>)
 >Re: NSDate Question (From: "Sean McBride" <email@hidden>)
 >Re: NSDate Question (From: Roland Torres <email@hidden>)
 >Re: NSDate Question (From: "Sean McBride" <email@hidden>)

  • Prev by Date: NSMenu question
  • Next by Date: Re: NSMenu question
  • Previous by thread: Re: NSDate Question
  • Next by thread: NSMenu question
  • Index(es):
    • Date
    • Thread