未归档的对象会发生什么情况?

发布于 2024-09-06 07:06:52 字数 2022 浏览 4 评论 0原文

使用 NSKeyedUnarchiver 取消归档对象后,我可以像平常一样使用它,但无法重新归档它。当我尝试时,它崩溃了。

[NSKeyedArchiver archiveRootObject:unarchivedObject toFile:fileName];

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

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

据我所知,这可能是我的声音课。当你检查这个的时候我会检查一下。

尽管如此,经过研究,我发现了这一点:

replacementObjectForKeyedArchiver:

在键控归档期间被子类覆盖以替换另一个对象本身。

  • (id)replacementObjectForKeyedArchiver:(NSKeyedArchiver *)archiver

参数 档案员 创建档案的带密钥的档案器。 返回值 对象编码而不是接收者(如果不同)。

<我> 讨论 仅当编码器中未设置对象的替换映射时才会调用此方法(例如,由于之前对该对象调用了 replacementObjectForKeyedArchiver:)。

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];

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

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

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


Discussion
This method is called only if no replacement mapping for the object has been set up in the encoder (for example, due to a previous call of replacementObjectForKeyedArchiver: to that object).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪之触 2024-09-13 07:06:52

Apple 开发论坛上的一个帖子似乎表明在您尝试编码的对象上调用了 replacementObjectForKeyedArchiver: 。听起来您尝试在 -[SoundsencodeWithCoder:] 内编码的对象之一已从内存中释放,并且 replacementObjectForKeyedArchiver: 正在被调用以导致段错误。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文