Re: Problem when archiving data: [_NSViewGState encodeWithCoder:] unrecognized selector
Re: Problem when archiving data: [_NSViewGState encodeWithCoder:] unrecognized selector
- Subject: Re: Problem when archiving data: [_NSViewGState encodeWithCoder:] unrecognized selector
- From: "Ken Ferry" <email@hidden>
- Date: Fri, 25 Jul 2008 21:33:56 -0700
> [coder encodeValueOfObjCType:@encode(NSNumber *) at:&magnitude];
This isn't encoding the number object, this is encoding the pointer to
the number object. When you get it out of the archive, you get the
same pointer as you put in, but that pointer points to some random bit
of memory in your app, not the number.
Use [coder encodeObject:] to encode objects.
Also, you're probably also better off using NSKeyedArchiver than
NSArchiver, and using encodePoint:forKey:, encodeObject:forKey:, etc.
The non-keyed archiver is not formally deprecated, but it shouldn't
really be used in new code. Newer Cocoa classes cannot generally be
encoded with the non-keyed archiver, and older classes do not
necessarily encode all of their data when written to a non-keyed
archive. Every time you encode something new in an encodeWithCoder:
method to a non-keyed archiver, it breaks the ability of older
versions of the class to read the archiver.
-Ken
On Fri, Jul 25, 2008 at 6:59 PM, Kyle Sluder
<email@hidden> wrote:
> On Fri, Jul 25, 2008 at 6:29 PM, JArod Wen <email@hidden> wrote:
>> Since I didn't find any object in the data to be written has the type of
>> NSViewGState, I am really confused about this error. Anyone can give me any
>> suggestions?
>
> This is usually a case of failing to retain an object you own. If it
> gets deallocated underneath your feet, an object of a different class
> may wind up in the same place in memory, but your old pointers don't
> know that. Often, because of the way the compiler has generated your
> code, it's consistently an object of a certain but completely
> unrelated class.
>
> --Kyle Sluder
> _______________________________________________
>
> 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
>
_______________________________________________
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