ios - initWithCoder : function is not called from unarchiveObjectWithData:

标签 ios objective-c persistence nskeyedarchiver nscoding

我正在尝试取消存档特定类型的对象数组,但 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/

相关文章:

ios - 如何在 iOS 中下载 YouTube 视频

iOS - Swift 是否与应用程序二进制文件或操作系统捆绑在一起

java - EntityManager em.remove() 和 em.persist() 未反射(reflect)在同一上下文中,而反射(reflect)了实体中的更改

java - JPA持久化 CrudRepository.save() 语法错误

android - 如何将 iOS Unity 游戏发送给赞助商/发行商

ios - SpriteKit 动画问题

ios - 获取 CGPath 总长度

ios - 如何在现有图像上添加水印

ios - 为什么此RELEASE不会产生RUNTIME ERROR?

java - Hibernate 注释 - 1 比 1,无 auto_increment