Re: Question about Archives and Serialisations Programming Guide
Re: Question about Archives and Serialisations Programming Guide
- Subject: Re: Question about Archives and Serialisations Programming Guide
- From: Quincey Morris <email@hidden>
- Date: Fri, 05 Feb 2016 09:04:51 -0800
- Feedback-id: 167118m:167118agrif8a:167118s0LuOpBEGg:SMTPCORP
On Feb 5, 2016, at 07:27 , Dave <email@hidden> wrote:
>
> If you set it strong, then it creates a dupe of the object over and over again, as I said in the other thread
a. If that’s the case, then your problem is nothing to do with the weak references. Something is causing those objects to be *either* archived as unique objects (copies) *or* copied after unarchiving. As others have repeatedly stated, object uniqueness *is* maintained through archiving and unarchiving, and if you’re following the idea that there’s something wrong with NSKeyedArchiver/NSKeyedUnarchiver, then you’re almost certainly barking up the wrong tree.
Your first task, therefore, is to find out whether copies of the object are being archived, or whether copies are being made after unarchiving.
(Here’s one scenario where it might happen on unarchiving: if some relevant property is marked ‘copy’. In that case, you need to ensure that in initWithCoder you store unarchived references into the instance variable, and not store them via the property. I doubt the real answer is that easy, but that’s the sort of thing to look for.)
b. There is no problem with archiving weak references. I’ve done it (for parent references in a hierarchical tree structure). Even though I don’t have the implementations of NSKeyedArchiver/NSKeyedUnarchiver, they have to work because they don’t *know* the objects being archived or unarchived are “weak”, because *objects* are not weak, only references to objects.
All the references to objects within NSKeyedArchiver/NSKeyedUnarchiver are strong. That’s why those classes have the idea of “conditional” objects, which is their mechanism for handling objects that are only weakly referenced in the part of an object graph that’s being archived and unarchived (and presumably strongly referenced only by transient references that don’t go into the archive).
_______________________________________________
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