• 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: Comment on archiving as an application file format
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comment on archiving as an application file format


  • Subject: Re: Comment on archiving as an application file format
  • From: "Timothy J. Wood" <email@hidden>
  • Date: Fri, 24 May 2002 19:35:44 -0700

On Friday, May 24, 2002, at 05:47 PM, Kirk Kerekes wrote:
[...]
The problem as I see it is that objects have a tendency to _change_ during the life of a software product -- features get added, bugs get fixed/introduced. And the requirement that IV's be encoded/decoded in precisely the same order (and size and number) to ensure basic file compatibility between application versions just seemed like a Bad Idea leading to Fragile File Format Syndrome.

Note that you can use -[NSCoder versionForClassName:] to have backwards compatibility. That is, you can do:

enum {
MyClassVersion0,
MyClassVersion1,
MyClassVersionCurrent = MyClassVersion1,
};

+ (unsigned int) version;
{
return MyClassVersionCurrent;
}

- (id) initWithCoder: (NSCoder *) coder;
{
switch([coder versionForClassName: @"MyClassName"]) {
case MyClassVersion0:
// read one way
break;
case MyClassVersion1:
// read another way
break;
default:
// raise an exception -- need to implement decoding for this version!
}
}

When your objects are encoded, the +version method is called and embedded in the encoded data. When you decode, you can figure out what version was encoded in the file and act accordingly.

This has a couple limitations -- you can't (AFAIK) have differing versions of objects in a single archive and you can't write anything other than your current version.

So I added a layer on top of the techniques in Hillegass -- I add an NSMutableDictionary and two methods to each of my classes that I want to be able to archive: setIVsFromDictionary and setDictionaryFromIVs. These methods store/retrieve the items to be archived in the NSMutableDictionary under private keys. As a matter of habit, I convert C numeric values into NSNumbers and less convenient oddball data-lumps into NSValue objects.

Then all I encode/decode is the dictionary itself.

You might want to sign up for an ADC membership and take a look at Jaguar when they send out CDs at some point.

An interesting idea was pointed out to me at WWDC by Michael Johnson -- it is often useful to write out old versions of your objects if you don't use any features of the newer versions. This is especially true if you work in a group environment and you want to make a small change to a file (and you are using 'new' tools) without forcing everyone else in the group to upgrade to the latest tools.

I like dictionary formats, certainly, but an actual versioning system is important, I think. This allows you to make assertions about what should or shouldn't be in the archive and allows for the possibility that two otherwise identical dictionaries should be interpreted differently (say, on version 1 you have "foo" and "bar" and then after 50 versions you are back to "foo" and "bar" but they have subtly different meanings ...)

In general, I'd sort of like a validating XML parser with each ObjC class having a set of per-version DTD fragments. This doesn't address inter-object validation, but it would be a good start.

-tim
_______________________________________________
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.

References: 
 >Comment on archiving as an application file format (From: Kirk Kerekes <email@hidden>)

  • Prev by Date: Re: Adding <NSCoding> to NSTextStorage, or not.
  • Next by Date: Re: cocoa-dev digest, Vol 2 #672 - 18 msgs
  • Previous by thread: Comment on archiving as an application file format
  • Next by thread: Re: cocoa-dev digest, Vol 2 #672 - 18 msgs
  • Index(es):
    • Date
    • Thread