【问题标题】:Archive a NSMutableArray归档一个 NSMutableArray
【发布时间】:2010-02-27 20:07:49
【问题描述】:

我需要归档一个由 ArrayController 控制的 NSMutableArray。我试过这个:

[NSKeyedArchiver archivedDataWithRootObject:array];

但是我收到了这个错误:

*** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it.

请问我该如何解决?

【问题讨论】:

  • 你的数组包含什么样的对象?你能确认所有对象都实现了 NSCoding 协议吗?

标签: objective-c cocoa arrays nsmutablearray nskeyedarchiver


【解决方案1】:

您正在归档的图形的根对象以及它所引用/包含的任何内容都必须符合 NSCoding> 协议。请参阅 Encoding and Decoding Objects 以获取使您的类兼容的代码示例(不要忘记在对象的接口声明中“采用”协议:@interface MyClass : NSObject < NSCoding >)。

【讨论】:

  • 这对我们没有帮助。 :-) 发布你的代码并描述它是如何不工作的。
  • 对不起,我忘了。我收到了这些错误:2010-02-28 22:22:18.145 我的应用程序 [53732:a0f] -[content encodeWithCoder:]: unrecognized selector sent to instance 0x100189740 2010-02-28 22:22:18.146 My app[53732: a0f] -[content encodeWithCoder:]: 无法识别的选择器发送到实例 0x100189740
  • 可能是个愚蠢的问题,但您是否真的为数组中的对象实现了encodeWithCoder: 方法?
  • 如果您发布相关代码,所有这些来回询问将完全没有必要。
  • 我只是注意到它不会发生在任何其他阵列上。问题是由阵列控制器控制的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多