Comment on archiving as an application file format
Comment on archiving as an application file format
- Subject: Comment on archiving as an application file format
- From: Kirk Kerekes <email@hidden>
- Date: Fri, 24 May 2002 19:47:40 -0500
Having attempted to implement an archiving scheme under the Think Class
Library many moons ago, I was quite pleased to see Cocoa's mature
implementation as I groped my way through Hillegass's book.
However, something about the way he presented the archiving of
instance-variables bugged me -- and that nagging quibble lead me to do
archiving in what I feel is a somewhat more robust way.
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.
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.
If a new version of my software adds an archived IV, an older version can
read the file without problems, so long as the new object is a proper
superset of the older version. Because the new IV is in a dictionary, the
old software will just never see it. This is fine, as it presumably has no
use for it anyway.
If a new version of my software reads an old file, it simply gets nil
responses from [NSDictionary objectForKey:] and deals with that
appropriately.
I can't find any serious gotchas to this technique that aren't already
present in the standard one.
Maybe everybody does this already, but I couldn't find any web-reference to
this technique with Google.
_______________________________________________
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.