未归档对象会发生什么? [英] What happens with unarchived objects?

查看:948
本文介绍了未归档对象会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用NSKeyedUnarchiver解除封存物件后,我可以照常使用,但我无法重新封存。当我尝试,它崩溃。

After I've unarchived an object with NSKeyedUnarchiver, I am able to use it like usual, but I am unable to re-archive it. When I try, it crashes.

[NSKeyedArchiver archiveRootObject:unarchivedObject toFile:fileName];

我尝试查看苹果的开发人员资源,但我还没有看到彻底解释正确的使用的NSKeyedArchiver。请帮助。

I tried looking in the developer resources in apple but I haven't seen a thorough explination of proper usage of NSKeyedArchiver. Please Help.

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000023
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Application Specific Information:
objc_msgSend() selector name: replacementObjectForKeyedArchiver:
iPhone Simulator 3.2 (193.8), iPhone OS 3.2 (iPad/7B367)

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x958a0ed7 objc_msgSend + 23
1   OGLGame                         0x0000c7e2 -[Sounds encodeWithCoder:] + 59 (Sounds.m:86)
2   Foundation                      0x0280d25b _encodeObject + 827
3   Foundation                      0x028243cc -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 284
4   Foundation                      0x0281a367 -[NSArray(NSArray) encodeWithCoder:] + 615
5   Foundation                      0x0280d25b _encodeObject + 827
6   OGLGame                         0x0000ebc2 -[Row encodeWithCoder:] + 244 (Row.m:153)
7   Foundation                      0x0280d25b _encodeObject + 827
8   Foundation                      0x028243cc -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 284
9   Foundation                      0x0281a367 -[NSArray(NSArray) encodeWithCoder:] + 615
10  Foundation                      0x0280d25b _encodeObject + 827
11  Foundation                      0x0285de10 +[NSKeyedArchiver archiveRootObject:toFile:] + 176

据我所知,是我的Sounds类。

As far as I can tell, it might be my Sounds class. I'll check it over while you check this over.

虽然经过研究,我发现:

Although, after research I found this:

replacementObjectForKeyedArchiver:

被子类覆盖以替换另一个对象

Overridden by subclasses to substitute another object for itself during keyed archiving.


  • (id)replacementObjectForKeyedArchiver:(NSKeyedArchiver *)archiver

参数
archiver
创建存档的键控存档。
返回值
对象编码而不是接收者(如果不同)。

Parameters archiver A keyed archiver creating an archive. Return Value The object encode instead of the receiver (if different).


讨论
方法仅在编码器中未设置对象的替换映射(例如,由于之前调用replacementObjectForKeyedArchiver:到该对象)时才被调用。

推荐答案

苹果开发论坛上的线程似乎表明 replacementObjectForKeyedArchiver:在您尝试编码的对象上调用。这听起来像你试图编码的对象之一 - [Sounds encodeWithCoder:] 已经释放内存和 replacementObjectForKeyedArchiver:

A thread on the Apple dev forums seems to indicate that replacementObjectForKeyedArchiver: is called on the objects you are attempting to encode. It sounds like one of the objects you are trying to encode inside -[Sounds encodeWithCoder:] has been freed from memory and replacementObjectForKeyedArchiver: is being called it on causing a seg fault.

https://devforums.apple.com/message/1079616

这篇关于未归档对象会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆