• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Archiving objects without their owner[1]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Archiving objects without their owner[1]


  • Subject: Re: Archiving objects without their owner[1]
  • From: Andre Lipinski <email@hidden>
  • Date: Fri, 21 Dec 2001 13:47:08 -0500

On Thursday, December 20, 2001, at 02:14 AM, Dan Bernstein wrote:


On Thursday, December 20, 2001, at 06:14 AM, Andre Lipinski wrote:


On Wednesday, December 19, 2001, at 01:59 AM, Dan Bernstein wrote:

On Wednesday, December 19, 2001, at 06:30 AM, Andre Lipinski wrote:

If you'd like to just handle one owner per archive, it's real easy, use replaceObject:[NSNull null] withObject: then decode the root object.

With multiple replaced things it's more tricky if you'd like some tips, please email.

Andre.

Thanks.

However, it doesn't seem to work for me. Here's what I did for archiving:

NSArchiver *myArchiver = [[[NSArchiver alloc] initForWritingWithMutableData:[NSMutableData data]] autorelease];
[myArchiver replaceObject:self withObject:[NSNull null]];
[myArchiver encodeRootObject:theRootObject];

I then store [myArchiver archiverData]. Here's how I unarchive:

NSUnarchiver *myUnarchiver = [[[NSUnarchiver alloc] initForReadingWithData:theData] autorelease];
[myUnarchiver replaceObject:[NSNull null] withObject:self];
theRootObject = [myUnarchiver decodeObject];

Yet the unarchived object contains pointers to <null> instead of to the object doing the unarchiving.

What's wrong?
Hmmmmm. The pointers are NULL or nil, not [NSNull null]? Alright, try something more complicated which will also work for multiple replacements.

I'm sorry. They were [NSNull null]. Now I did this:

id placeHolder = @"ownerPH"
NSArchiver *myArchiver = [[[NSArchiver alloc] initForWritingWithMutableData:[NSMutableData data]] autorelease];
[myArchiver encodeObject:placeHolder];
[myArchiver replaceObject:self withObject:placeHolder];
[myArchiver encodeRootObject:theRootObject];

I then store [myArchiver archiverData]. Here's how I unarchive:

NSUnarchiver *myUnarchiver = [[[NSUnarchiver alloc] initForReadingWithData:theData] autorelease];
id placeHolder = [myUnarchiver decodeObject];
[myUnarchiver replaceObject:placeHolder withObject:self];
theRootObject = [myUnarchiver decodeObject];

Which results in @"ownerPH" being unarchived back into placeHolder, but also in all the pointers pointing to it, rather than to self, i.e. my [NSUnarchiver replaceObject:withObject:] is simply ignored :-(

Looks like a bug. report it at radar web. Sorry.

Andre.


References: 
 >Re: Archiving objects without their owner[1] (From: Dan Bernstein <email@hidden>)

  • Prev by Date: Re: FW-UP Multiple NSWindowcontroller for the same NSDocument
  • Next by Date: Merry Christmas everyone
  • Previous by thread: Re: Archiving objects without their owner[1]
  • Next by thread: Re: Archiving objects without their owner[1]
  • Index(es):
    • Date
    • Thread