我正在尝试取消存档特定类型的对象数组,但 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 - initWithCoder : function is not called from unarchiveObjectWithData:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19732315/