views:

27

answers:

2

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).

A: 

Have you read this Apple doc on the NSKeyedArchiver? Let me apologize in advance if you read it and didn't find it a through explanation.

And please post the (relevant part of the) crash report whenever you ask a question about the crash. We're not psychics and don't have the access to the crash report which often contains a lot of important clues to the crash.

Yuji
A: 
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).

Dane Man
Please edit your answer to include this information instead of adding an answer. Thanks! :-)
Steven Schlansker