Re: Problem Archiving/Un-archiving Custom Objects
Re: Problem Archiving/Un-archiving Custom Objects
- Subject: Re: Problem Archiving/Un-archiving Custom Objects
- From: Quincey Morris <email@hidden>
- Date: Thu, 21 Jan 2016 15:04:28 -0800
- Feedback-id: 167118m:167118agrif8a:167118sLTZHyw3Wm:SMTPCORP
On Jan 21, 2016, at 13:47 , Dave <email@hidden> wrote:
>
> myObjectCopy. pNodeIndexPath = self. pNodeIndexPath; //Copy Attribute on Property
You have to be careful, depending on what’s already happened. If the object was copied with NSCopyObject, which might have happened in NSObjet’s copyWithZone method even if you didn’t call it directly, instance variables will contain valid but unretained pointers. Because you’re assigning to a property, the existing underlying instance variable will have its retain count decremented, which probably isn’t the right thing to do.
Your copyWithZone method is more like an init method than a regular method. In general, like in inits, you will want to assign directly to instance variables rather than use property setters. In addition, you may have to deal manually with retain counts.
Yes, copyWithZone is a potential nightmare. In many cases, it’s easier not to copy anything really, but to create a new object whose instance variables you set up in a proper ‘initAsCopyOf:’ method that follows normal init conventions.
_______________________________________________
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