Re: ARCHIVING WITH CIRCULAR REFERENCES
Re: ARCHIVING WITH CIRCULAR REFERENCES
- Subject: Re: ARCHIVING WITH CIRCULAR REFERENCES
- From: Martin Häcker <email@hidden>
- Date: Sun, 16 Feb 2003 10:25:18 +0100
So anyway, I plead ingnorance on this one because I've read
everything I can find, web or hard-copy. If you could give an
example...or rather, using the example I gave and get it to archive
and unarchive...with the simple three object graph (array, holding
two NSDictionarys) still intact, I'd be very grateful!!
Well, this sure does look like it should already work for you:
--- snip ---
Root Object
An object graph is not necessarily a simple tree structure. Two
objects can contain references to each other, for example, creating a
cycle. If a coder follows every link and blindly encodes each object
it encounters, this circular reference will generate an infinite loop
in the coder. Also, a single object can be referenced by several
other objects. The coder must be able to recognize and handle
multiple and circular references so that it does not encode more than
one copy of each object, but still regenerate all the references when
decoding.
To solve this problem, NSCoder introduces the concept of a root
object. The root object is the starting point of an object graph. To
encode an object graph, you invoke the NSCoder method
encodeRootObject: , passing in the first object to encode. Every
object encoded within the context of this invocation is tracked. If
the coder is asked to encode an object more than once, the coder
encodes a reference to the first encoding instead of encoding the
object again.
NSCoder does not implement support for root objects; NSCoder's
implementation of encodeRootObject: simply encodes the object by
invoking encodeObject: . It is the responsibility of its concrete
subclasses to keep track of multiple references to objects, thus
preserving the structure of any object graphs.
--- snap ---
cu Martin
--
dont.wanna.tell
[ot]coder - hehe
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.