为什么我收到“不支持归档”在我的 NSWindow 子类中?

发布于 2024-08-14 12:59:47 字数 1099 浏览 2 评论 0原文

我有以下课程:

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

...但是 [superencodeWithCoder: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)

... NOT 只是 “符合 NSCoding” - 所以我猜这是否意味着只有 NSResponder 位符合 NSCoding 吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听,心雨的声音 2024-08-21 12:59:47

直接来自 NSWindow 文档:

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

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.

巴黎夜雨 2024-08-21 12:59:47

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

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

岁月如刀 2024-08-21 12:59:47

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文