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

ARCHIVING WITH CIRCULAR REFERENCES


  • Subject: ARCHIVING WITH CIRCULAR REFERENCES
  • From: Generic User <email@hidden>
  • Date: Sat, 15 Feb 2003 12:03:18 -0600

Hello all,

I have a simple little app that saves/reads a relatively simple object
graph to/from disk using standard Cocoa techniques
(NSArchiver/NSUnarchiver). The object graph does contain circular
references but has, I"M FAIRLY CERTAIN, always worked with no problem.
I've tested it and when opening a saved file, the model (object-graph)
looks just like it should. However, today, it quit working. Yes, I've
made changes to the app but nothing to the archiving portions, haven't
added any new objects to the graph, and everything in the graph
conforms to NSCoding, in fact, it's mostly Cocoa collection classes.
So, today, it breaks, the only thing really new is that I installed the
Dec Dev Tools a few days ago. Since sending actual snippets of code is
impractical, I have a contrived example below..along with output. If
anyone knows why this doesn't work, I'd love to know too!! Any advice
is appreciated.

*********************************
Build a circular graph
*********************************
NSMutableDictionary *a = [NSMutableDictionary
dictionaryWithObjectsAndKeys:@"",@"name",nil];
NSMutableDictionary *b = [NSMutableDictionary
dictionaryWithObjectsAndKeys:a,@"name",nil];
[a setObject:b forKey:@"name"];
NSArray *c = [NSArray arrayWithObjects:a,b,nil];
NSLog(@"%x",[c objectAtIndex:0]);
NSLog(@"%x",[c objectAtIndex:1]);
NSLog(@"%x",[[c objectAtIndex:0] objectForKey:@"name"]);
NSLog(@"%x",[[c objectAtIndex:1] objectForKey:@"name"]);

NSData *dd = [NSArchiver archivedDataWithRootObject:c];
NSArray *ee = [[NSUnarchiver unarchiveObjectWithData:dd] retain];

NSLog(@"%x",[ee objectAtIndex:0]);
NSLog(@"%x",[ee objectAtIndex:1]);
NSLog(@"%x",[[ee objectAtIndex:0] objectForKey:@"name"]);
NSLog(@"%x",[[ee objectAtIndex:1] objectForKey:@"name"]);

NSLog(@"%x",[[[ee objectAtIndex:0] objectForKey:@"name"]
objectForKey:@"name"]);
NSLog(@"%x",[[[ee objectAtIndex:1] objectForKey:@"name"]
objectForKey:@"name"]);

******************************************************
the output
******************************************************

2003-02-12 17:43:18.202 mytest[1448] 31d3d0
2003-02-12 17:43:18.203 mytest[1448] 31d590
2003-02-12 17:43:18.203 mytest[1448] 31d590
2003-02-12 17:43:18.203 mytest[1448] 31d3d0
2003-02-12 17:43:18.206 mytest[1448] 313500
2003-02-12 17:43:18.206 mytest[1448] 313470
2003-02-12 17:43:18.207 mytest[1448] 313470
***2003-02-12 17:43:18.207 mytest[1448] 1b4460***
2003-02-12 17:43:18.207 mytest[1448] 1b4460
2003-02-12 17:43:18.208 mytest[1448] *** -objectForKey: sent to an
uninitialized mutable dictionary object

THE *** LINE JUST ISN'T RIGHT, AS IF THE OBJECT IT'S POINTING TO IS
STILL INSIDE THE CODER OR SOMETHING...COMPLETELY DIFFERENT ZONE.

This is such a trivial model to archive, I must be doing something
wrong and it really never worked, I just thought it did??

Help?!
_______________________________________________
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: Alex Rice <email@hidden>
  • Prev by Date: Re: Get path to user preference folder
  • Next by Date: Re: ProjectBuilder
  • Previous by thread: Re: Get path to user preference folder, updated
  • Next by thread: Re: ARCHIVING WITH CIRCULAR REFERENCES
  • Index(es):
    • Date
    • Thread