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: Martin Wierschin <email@hidden>
- Date: Mon, 01 Aug 2011 12:45:48 -0700
>>> 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…
>
> Thank you, Jens. I see the problem.
>
> Here's a fairly radical solution:
...
> @implementation NSObject (LookMaNoEncodingExceptions)
>
> - (void)encodeWithCoder:(NSCoder*)coder {
> NSString* archivoid = [NSString stringWithFormat:
> @"Sorry, %@ is not encodable.\n"
> @"Here's a description of it: %@",
> [self className],
> [self description]] ;
> [coder encodeObject:archivoid
> forKey:@"Archivoid"];
> }
This is even worse than the original problem. Rather than getting an exception at the time of encoding, now you're silently converting unencodable objects to strings. When you unarchive one of those strings, code expecting an instance of UnencodableFoo will instead have an NSString, the use of which will likely throw exceptions, eg: when code calls -[UnencodableFoo fooThing]
~Martin
_______________________________________________
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