• 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 WITH CIRCULAR REFERENCES
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ARCHIVING WITH CIRCULAR REFERENCES


  • Subject: Re: ARCHIVING WITH CIRCULAR REFERENCES
  • From: Generic User <email@hidden>
  • Date: Sat, 15 Feb 2003 23:02:44 -0600

Thanks Alex,

Only, I don't think conditional encoding will solve this problem. It seems to me that conditional encoding is for ensuring objects do NOT get encoded...in my case, I want it all encoded unconditionally. To restate the problem, look at it this way: two NSDictionarys are in an NSArray. NSD 1 points to NSD 2 and NSD 2 points to NSD 1. The NSArray should archive just fine and the key, in NSD 2, that points to NSD 1, would not actually re-encode the object (NSD 1) but simply create a token...a "proxy pointer" if you will. When it's all un-archived, the proxy pointer needs to be set to point to the location where NSD 1 was instantiated. This isn't happening in my example though. I'm either way wrong about how this is supposed to work, or it simply doesn't work correctly.
BTW, if you simply create a NIB file with a single window, you have an archive with circular reference, the window has a pointer to the content view, and the content view to the window. So it definitely is done all the time using NSArchiver...which is what IB uses I think.

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!!

dan


On Saturday, February 15, 2003, at 06:59 PM, Alex Rice wrote:


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.

  • Follow-Ups:
    • Re: ARCHIVING WITH CIRCULAR REFERENCES
      • From: Martin Häcker <email@hidden>
References: 
 >Re: ARCHIVING WITH CIRCULAR REFERENCES (From: Alex Rice <email@hidden>)

  • Prev by Date: Re: IB is confused (or I am :-)
  • Next by Date: Re: IB is confused (or I am :-)
  • Previous by thread: Re: ARCHIVING WITH CIRCULAR REFERENCES
  • Next by thread: Re: ARCHIVING WITH CIRCULAR REFERENCES
  • Index(es):
    • Date
    • Thread