Re: Problem Archiving/Un-archiving Custom Objects
Re: Problem Archiving/Un-archiving Custom Objects
- Subject: Re: Problem Archiving/Un-archiving Custom Objects
- From: Dave <email@hidden>
- Date: Thu, 21 Jan 2016 23:22:47 +0000
> On 21 Jan 2016, at 23:04, Quincey Morris <email@hidden> wrote:
>
> On Jan 21, 2016, at 13:47 , Dave <email@hidden <mailto: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.
>
Yes, I came to that conclusion too and I added a initWithIndexPath method to an NSIndexPath Category and it works!
I was manually copying the dictionaries and arrays anyway - [xxxxx mutableCopy];
I did that and Bang it Crashed about, but this time with another bug which was easy to find since malloc guard caught it this time, that one was a flakey method for converting an NSString “xx.yy.zz" type string an Array of NSUInteger’s to call initWithIndexs with!
Fixed that one and now it work!
Thanks a lot Jens and Qunicey………
One quick question, I’m relying of the copy attribute for the NSString’s, do I need to change these to do a [xxxxxxx copy] too or is NSString OK?
All the Best
Dave
_______________________________________________
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