views:

98

answers:

3

Hi all - 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 ?

+1  A: 

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

Azeem.Butt
I have both :- (id) initWithCoder:(NSCoder *)aDecoder;- (void) encodeWithCoder:(NSCoder *)aCoder;... given that I can tell my encodeWithCoder is getting called (via the NSLog statement I'm assuming this isn't the issue (but thanks for thinking of this :-) )
Dave Carpeneto
A: 

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

Dave Carpeneto
I'm pretty sure NSView does, but you're right that NSWindow does not. IB and the nib system in AppKit do special magic to store what appear to be NSWindow instances in nib archives; they do not actually put an NSWindow instance through the usual archiving API.
Peter Hosey
+3  A: 

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.

Mike Abdullah