Indeed

Things that seemed important enough at the time

Monday, November 29, 2004

Programming poll #1: Archiving

I spent a good portion of the extended weekend coding up some stuff that I haven't had much time for recently, and it was pretty fun (and frustrating... as usual). I was working on the saving code for a project, and it took me a while to come up with a solution that worked well - so I'm interested in hearing what other people do...

My old program saved my document to disk via the 'archivedDataWithRootObject:' method from NSKeyedArchiver - where I would take all of the objects I cared about, add them into an array, and pass that array as the root object. That was ok originally, since it was just me dealing with the documents, but I'm trying to be a little more 'future-proof' with this. I realized that I wasn't getting any of the keyedarchiver benefits, so I set about trying to make my document archiving better.

It should be noted that I've done a whole bunch of little programming side projects to learn parts of Cocoa, but very few of them dealt with saving or opening archived data that I created... so this is all a little unfamiliar.

My initial thought was to add the usual 'encodeWithCoder:' and 'initWithCoder:' methods to my NSDocument subclass, but I didn't really get that to work well. I ended up creating my own NSKeyedArchiver/Unarchiver objects within my 'dataRepresentationOfType:'/'loadDataRepresentation:ofType:' methods, which is working so far. It just seemed weird to actually allocate the NSKeyed objects, since the class methods usually do the trick.

Any thoughts from other people that have done this? I didn't find anything useful in the developer examples (Sketch seemed a little overly complex), and usually I'd check my Hillegass book, but Ethan has it at the moment.

0 Comments:

Post a Comment

<< Home

 
Google