OGeek|极客世界-中国程序员成长平台

标题: ios - initWithCoder : function is not called from unarchiveObjectWithData: [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:07
标题: ios - initWithCoder : function is not called from unarchiveObjectWithData:

我正在尝试取消归档特定类型的对象数组,但 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: 行与上面的错误一致,但似乎甚至没有在我的类(class)上调用 initWithCoder:。

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



Best Answer-推荐答案


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

关于ios - initWithCoder : function is not called from unarchiveObjectWithData:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19732315/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4