On Jul 10, 2014, at 4:57 PM, Ken Thomases <k...@codeweavers.com> wrote:

> Are the items that result from unarchiving the persistent object the same 
> items as your data source returns via -outlineView:child:ofItem:?  I believe 
> they have to be the same by pointer identity, not just equal as by -isEqual:.

They are content-equal, but they can't be pointer-identical because I archive 
them to NSData objects and unarchive them using NSKeyedArchiver and 
NSKeyedUnarchiver. The reference document comes as close as possible to saying 
that we're supposed to use NSKeyedArchiver and NSKeyedUnarchiver  without quite 
actually saying so. For example, according to the NSOutlineViewDataSource 
reference for -outlineView:persistentObjectForItem:, the return value should be 
"An archived representation of item." If this means we should use 
NSKeyedArchiver, which I assume it does, then pointer-identity couldn't be a 
requirement, could it? There is nothing in the reference document to suggest 
that pointer-identity is required, for what that's worth.

My items are standard NSDictionary objects, and I have confirmed that they are 
properly reconstituted in -outlineView:itemForPersistentObject.

> Rather than archiving the item itself, you should perhaps archive uniquely 
> identifying attributes of the item so that you can find the corresponding 
> item among the new model and return that.

Online discussions of this problem in the past have suggested that archiving 
unique strings works, and discussions in the Core Data context have suggested 
that using UUIDs works. But the reference document makes no suggestion that 
this is required. In fact, just after the quotation above, it goes on to say 
"If the item is an archived object, this method may return the item." Having to 
implement UUIDs in my data source for the sole purpose of implementing 
expand/collapse state survival across application relaunches seems a bit much.

I did try calling -outlineView:itemForPersistentObject: myself in 
-awakeFromNib, matching the unarchived items to their counterparts in the 
datasource and loading the object from the datasource, and it didn't work. 
However, that was late in the day yesterday and I may not have gotten it quite 
right. I'll try again this morning. But this seems counter-intuitive, because I 
have confirmed that AppKit calls -outlineView:itemForPersistentObject: itself 
at launch, once for each archived item in user defaults. The documentation does 
not suggest in any way that I should call it myself, which would be counter to 
the normal behavior of datasource methods.

-- 

Bill Cheeseman - b...@cheeseman.name

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to