Re: ARCHIVING WITH CIRCULAR REFERENCES
Re: ARCHIVING WITH CIRCULAR REFERENCES
- Subject: Re: ARCHIVING WITH CIRCULAR REFERENCES
- From: Alex Rice <email@hidden>
- Date: Sat, 15 Feb 2003 17:59:58 -0700
On Saturday, February 15, 2003, at 11:03 AM, Generic User wrote:
If anyone knows why this doesn't work, I'd love to know too!!
I could be wrong, but, circular object graphs are not a trivial
problem. In think the encodeConditionalObject: stuff in NSArchiver is
a way to workaround your problem. Although you may have to write your
own classes.
"""
Conditional Objects
Another problem presented by object graphs is that it is not always
appropriate to archive the entire graph. For example, when you encode
an NSView object, the view can have many links to other objects:
subviews, superviews, formatters, targets, windows, menus, and so on.
If a view encoded all of its references to these objects, the entire
application would get pulled in. Some objects are more important than
others, though. A view's subviews always should be archived, but not
necessarily its superview. In this case, the superview is considered an
extraneous part of the graph; a view can exist without its superview,
but not its subviews. A view, however, needs to keep a reference to its
superview, if the superview is also being encoded in the archive.
To solve this dilemma, NSCoder introduces the concept of a conditional
object. A conditional object is an object that should be encoded only
if it is being encoded unconditionally elsewhere in the object graph. A
conditional object is encoded by invoking the NSCoder methods
encodeConditionalObject: and encodeConditionalObject:forKey:. If all
requests to encode an object are made with these conditional methods,
the object is not encoded and references to it decode to nil. If the
object is encoded elsewhere, all the conditional references decode to
the single encoded object.
Typically, conditional objects are used to encode weak, or nonretained,
references to objects.
NSCoder does not implement support for conditional objects; NSCoder's
implementations of encodeConditionalObject: and
encodeConditionalObject:forKey: simply encode the object by invoking
encodeObject: or encodeObject:forKey:. It is the responsibility of its
concrete subclasses to keep track of conditional objects and to not
encode objects unless they are needed. Both NSArchiver and
NSKeyedArchiver provide full support for conditional objects.
"""
Alex Rice <email@hidden> | Mindlube Software |
http://mindlube.com
what a waste of thumbs that are opposable
to make machines that are disposable -Ani DiFranco
_______________________________________________
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.