Question

I have the following class:

@interface SpWindow : NSWindow <NSCoding> {
  BOOL _editMode;
  SpBgView *bgView;
} ...

... which I then call archive on. My encode method is as follows:

- (void) encodeWithCoder:(NSCoder *)aCoder {
  NSLog(@"encodeWithCoder CALLED FOR SpWindow");
  [super encodeWithCoder:aCoder];
  NSLog(@"SpWindow's encodeWithCoder got past the super call");  
  [aCoder encodeObject:bgView forKey:@"bgView"];
  [aCoder encodeBool:_editMode forKey:@"_editMode"];  
}

... however the [super encodeWithCoder:aCoder]; bit results in the following in the console log:

encodeWithCoder CALLED FOR SpWindow
<SpWindow: 0x20009f660> does not support archiving
*** -[NSKeyedArchiver finalize]: warning: NSKeyedArchiver finalized without having had -finishEncoding called on it.

... according to the NSWindow documentation the class conforms to the NSCoding protocol, so I have no idea why I'm seeing this issue.

Any ideas ?

--- EDIT: The class reference for NSWindow shows:

Conforms to NSCoding (NSResponder)

... NOT just "Conforms to NSCoding" - so I guess does this mean that only the NSResponder bits conform to NSCoding ?

Was it helpful?

Solution

Straight from the NSWindow documentation:

Note: Although the NSWindow class inherits the NSCoding protocol from NSResponder, the class does not support coding. Legacy support for archivers exists but its use is deprecated and may not work. Any attempt to archive or unarchive an NSWindow object using a keyed coding object raises an NSInvalidArgumentException exception.

OTHER TIPS

Does your class implement the entire protocol or just encodeWithCoder? Methods marked "required" are not optional.

OK, it looks like I'm a victim of my meddling with the MVC-model - NSview & NSWindow don't do the NSCoding thing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top