Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Archiving and NSView Subclasses



Thanks everyone who responded to my earlier issue. Seems I did something rather stupid, which was to add the view I was palettizing to the wrong target - the palette rather than the framework target.

Now I've hit something frustrating, and I hope it's not something just as stupid. My palette is working great - I've got bindings working, the inspector working, everything seems great until I go to run a program that uses the palettized view. When the program launches, I get a SIGTRAP after getting this error message:

2005-08-30 19:10:59.144 SWSpiralViewTester[2467] An uncaught exception was raised
2005-08-30 19:10:59.145 SWSpiralViewTester[2467] *** - [NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (SWSpiralView)
2005-08-30 19:10:59.146 SWSpiralViewTester[2467] *** Uncaught exception: <NSInvalidUnarchiveOperationException> *** - [NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (SWSpiralView)


Now, I've implemented initWithCoder: and encodeWithCoder: for this view, and support keyed archiving in them. I peppered the methods with NSLog calls, and everything is working as expected within Interface Builder, but my initWithCoder does not appear to be getting called before the error above - I can't find evidence of the NSLog entries (which I didn't include in the code sample below) for initWithCoder: in my application's run log, or anywhere in Console.app (not sure where it would go being code from a framework - the entries go into Console.app when I'm running IB).

Here's the NSCoding methods I've implemented:

- (void)encodeWithCoder:(NSCoder *)coder
{
    [super encodeWithCoder:coder];
    if ([coder allowsKeyedCoding])
    {
    [coder encodeObject:[self color] forKey:@"color"];
    [coder encodeInt:[self gap] forKey:@"gap"];
    }
    else
    {
    [coder encodeObject:[self color]];
    [coder encodeValueOfObjCType:@encode(int) at:&gap];
    }
}
- (id)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self)
    {
    if ([coder allowsKeyedCoding])
    {
        [self setColor:[coder decodeObjectForKey:@"color"]];
        [self setGap:[coder decodeIntForKey:@"gap"]];
    }
    else
    {
        [self setColor:[coder decodeObject]];
        [coder decodeValueOfObjCType:@encode(int) at:&gap];
    }

    }
    return self;
}

If anyone knows what I'm doing wrong, I'd love to hear it.

Thanks,
Jeff
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.