【问题标题】:The initWithCoder: function is not called from unarchiveObjectWithData:initWithCoder: 函数不是从 unarchiveObjectWithData 调用的:
【发布时间】:2013-11-01 17:47:13
【问题描述】:

我正在尝试取消归档特定类型的对象数组,但 initWithCoder: 函数未在对象的类中执行。相反,我得到了错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SavedObject initWithCoder:]: unrecognized selector sent to instance 0x9e85f34'

现在,奇怪的是,调用了 encodeWithCoder: 并且我能够将数据写入磁盘就好了。然后在尝试读回数据时,数据看起来与写入磁盘的数据完全相同。

写入磁盘:

// arrayOfObjectsToSave
NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:arrayOfObjectsToSave];
// uses NSData writeToURL - Works fine!
[self writeToDisk:arrayData];

通过控制台中的 po 命令,我可以确认 arrayData 看起来类似于:

<62706c69 73743030 ... 00000000 00000288>

读回数据:

// url passed through
NSData *readBack = [self readDataFromURL:dataURL];
NSArray *persisitedArray = [NSKeyedUnarchiver unarchiveObjectWithData:readBack]

回读数据为:

<62706c69 73743030 ... 00000000 00000288>

但应用程序似乎在 unarchiveObjectWithData: 行与上述错误一致,但似乎甚至没有在我的班级上调用 initWithCoder:。

最重要的是......它在 iOS 7 上运行良好

【问题讨论】:

  • 你说它可以在 iOS 7 上工作。它在哪里不工作?
  • 似乎不适用于 iOS 6。

标签: ios objective-c persistence nskeyedarchiver nscoding


【解决方案1】:

我已经通过重命名类实体来解决这个问题。现在所有现有代码都按预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多