Re: Using proxy objects with NSMutableArray
Re: Using proxy objects with NSMutableArray
- Subject: Re: Using proxy objects with NSMutableArray
- From: John Shockey <email@hidden>
- Date: Fri, 13 Jul 2007 07:49:32 -0400
On Jul 13, 2007, at 2:50 AM, Michael Tyson wrote:
Hi!
I'm archiving an NSMutableArray object to a file; the array
contains some objects of a certain class. The objects in the array
are actually stored elsewhere, within their own separate bundles,
so I don't want them actually archived - I just want placeholders.
So, I'm using a willEncodeObject delegate method to save a proxy
object instead, which just contains the identifier of the object
being archived. Then, I use a didDecodeObject delegate method to
look up the real object, load it, and return it instead of the proxy
However, I'm getting some odd behaviour - I seem to be getting back
not the mutable array, but the last object in the array.
The archiving process seems to be fine; if I archive a list with
two FLFeed items, and I unarchive with the delegate disabled, I get
back the mutable array with two FLFeedProxy items.
However, if I unarchive with the didDecodeObject delegate enabled,
I just get a single FLFeed (the last one in the saved list).
Any ideas?
I'm not absolutely certain of the specific symptom, but I do see a
definite problem.
You're trying to use "nil" for cases where the real archived object
can't be found. But putting "nil" into an NSArray (or NSMutableArray)
isn't allowed. The behavior in that case is undefined, and is
probably the cause of what you're seeing.
Instead, you could have "unarchiver:didDecodeObject:" return an
NSNull object, and then look for and remove those in your
"readFromDisk" method. Alternatively, leave the proxy objects alone
if you can't find the original object, and look for and remove those
in "readFromDisk" instead.
Presumably you're also having some problem with the way your proxy
works which is causing the original objects to be unavailable when
you unarchive, but you don't show enough code to see the cause of that.
John Shockey
john ATSIGN johncshockey DOT com
_______________________________________________
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