1

我有以下课程:

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

...然后我将其称为存档。我的编码方法如下:

- (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"];  
}

...但是该[super encodeWithCoder:aCoder];位会在控制台日志中产生以下结果:

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

...根据 NSWindow 文档,该类符合 NSCoding 协议,所以我不知道为什么会看到这个问题。

有任何想法吗 ?

--- 编辑: NSWindow 的类参考显示:

Conforms to NSCoding (NSResponder)

...只是"Conforms to NSCoding"-所以我想这是否意味着只有 NSResponder 位符合 NSCoding ?

4

3 回答 3

4

直接来自 NSWindow 文档:

注意:虽然 NSWindow 类继承了 NSResponder 的 NSCoding 协议,但该类不支持编码。存在对归档器的传统支持,但不推荐使用它并且可能无法正常工作。任何使用键控编码对象归档或取消归档 NSWindow 对象的尝试都会引发 NSInvalidArgumentException 异常。

于 2009-12-16T23:46:49.477 回答
1

你的班级是实现整个协议还是仅仅实现了encodeWithCoder?标记为“必需”的方法不是可选的。

于 2009-12-16T20:10:10.390 回答
-1

好的,看起来我是我干预 MVC 模型的受害者 - NSview 和 NSWindow 不做 NSCoding 的事情。

于 2009-12-16T21:48:15.557 回答