未归档的对象会发生什么情况?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 andreplacementObjectForKeyedArchiver:
is being called it on causing a seg fault.https://devforums.apple.com/message/1079616