Re: Re: Re: Re: Re: What is serializaton?
Re: Re: Re: Re: Re: What is serializaton?
- Subject: Re: Re: Re: Re: Re: What is serializaton?
- From: "Michael Ash" <email@hidden>
- Date: Mon, 24 Jul 2006 18:56:12 -0400
On 7/24/06, Corey O'Connor <email@hidden> wrote:
On 7/24/06, Michael Ash <email@hidden> wrote:
> Or you can just use NSCoder to do all the heavy lifting for you.
According to the documentation an NSCoder implementation calls -
(void) encodeWithCoder: (NSCoder*) on the object that was requested to
be serialized and initWithCoder on an object to be deserialized. The
object still has to determine how it's particular instance variables
should be serialized and de-serialized. As I understand it, no special
magic occurs to serialize and deserialize classes without relying on
the programmer of a class explicitly implementing routines to
serialize and de-serialize an instance of a class. Properly
serializing and deserializing an arbitrary object graph is not
something provided for free. Figuring out how to do that is also most
of the work of any data marshaling implementation IMO. To me, that
means that NSCoder does do any "heavy lifting". More like it: NSCoder
provides a nice framework for implementing data marshaling where the
specifics of marshaling an object's instance variables is left up to
the programmer.
Writing initWithCoder: and encodeWithCoder: methods is trivial,
though, if slightly boring. It would be pretty simple to write a
script that would parse your ivars and come up with implementations
that would work for most classes, and it's feasible to write a class
where all subclasses automatically get reasonable behavior for their
ivars without having to write anything.
But even without that, writing it manually is dead easy. The heavy
lifting comes in creating the data structures to store all of it,
particularly when dealing with cyclic graphs. As someone who has
actually written a concrete NSCoder subclasses (two, actually, one
archiver and one unarchiver) I can state that I have spent far more
time writing my one NSCoder than I have ever spent writing
initWithCoder: or encodeWithCoder: methods.
The documentation points out that 10.1 and earlier supported the
serialization of arbitrary objects without explicit programmer
support, but is deprecated now. So I'll just say that it doesn't
exists. :-)
Where does it state this? I looked around briefly and couldn't find
any such mention, and I'm curious to see what it has to say.
Automatic encoding tends to run into problems with complex classes,
and it can really have problems when you get into versioning and
support for archives created with old software. For this reason I'm a
fan of Apple's do-it-yourself method.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden