• 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: copyWithZone - if anyone could explain this to me ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copyWithZone - if anyone could explain this to me ?


  • Subject: Re: copyWithZone - if anyone could explain this to me ?
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Mon, 30 Nov 2009 21:11:58 -0800



Sent from my iPhone

On Nov 30, 2009, at 17:26, Jeff Laing <email@hidden> wrote:

In most cases, yes. However, copyWithZone: is special, the superclass'
implementation just blindly copies all of the raw bits in the source
object to the newly created one. If you were to use the normal
-setImage: call, that old value would be released one too many times.
Assigning to the instance variable in this case is the way to avoid
that.

Why would you not just do:

   [cell->image retain];

That makes it a lot clearer to me - since it was a bitwise copy, cell->image and image are identical values whereas the assignment looks like you are changing something.

Because it may *not* have been a bitwise copy. The superclass may have either done a bitwise copy of the whole object (the common case, I believe) or it may have only copied its *own* instance variables (in which case, cell->image will be nil). It's because of this uncertanty of which method the superclass uses that this, admittedly ugly, bit of code is used.


Generally, this is only an issue for people implementing copyWithZone: on an object that does not inherit directly from NSObject. _______________________________________________

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


  • Follow-Ups:
    • RE: copyWithZone - if anyone could explain this to me ?
      • From: Jeff Laing <email@hidden>
References: 
 >copyWithZone - if anyone could explain this to me ? (From: Mario KuĆĄnjer <email@hidden>)
 >Re: copyWithZone - if anyone could explain this to me ? (From: Clark Cox <email@hidden>)
 >RE: copyWithZone - if anyone could explain this to me ? (From: Jeff Laing <email@hidden>)

  • Prev by Date: Re: How to draw text to bitmap (array) with pre 10.5 libs
  • Next by Date: Re: NSAffineTransform scaleBy not scaling
  • Previous by thread: Re: copyWithZone - if anyone could explain this to me ?
  • Next by thread: RE: copyWithZone - if anyone could explain this to me ?
  • Index(es):
    • Date
    • Thread