Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
- Subject: Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
- From: Jens Alfke <email@hidden>
- Date: Sat, 30 Jul 2011 23:00:08 -0700
On Jul 30, 2011, at 10:21 PM, Jerry Krinock wrote:
> I don't think so, Jens. "They" is Apple. Apple has the source code for -initWithCoder: and -encodeWithCoder:.
No they don’t — not for the implementations of those methods in our own classes. Anyone implementing an archivable class has to create custom implementations of those methods. Apple has no idea what those methods look like, and most importantly, what other objects they might try to archive.
So consider you have an NSArray that contains a Foo object. Foo is some 3rd party class that implements NSCoding. The Foo object has a reference to an NSDictionary, one of whose keys is a Bar object. Bar isn’t archivable.
So now you call +isEncodable: with that array. The best Apple (aka the Foundation framework) can do is to find that your Foo object is going to be archived since it’s in the array. Without calling into -[Foo encodeWithCoder:] it can’t possibly tell that Foo is going to try to archive that array it has, which contains the unarchivable Bar object. But if it does call into Foo, it’s eventually going to find itself trying to archive the Bar object and have no way to signal failure short of throwing an exception.
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden