I'm was writing unit tests and when I encountered a strange behaviour of NSKeyedArchiver/NSKeyedUnarchiver. The following is a failing test. Am I doing wrong?
Here is a simple project to play with: https://github.com/genesislive2007/Archiving-Headache
-(void)test {
NSData* serializedObject = [NSKeyedArchiver archivedDataWithRootObject:[Drug new]];
id deserializedObject = [NSKeyedUnarchiver unarchiveObjectWithData:serializedObject];
XCTAssertTrue([deserializedObject isKindOfClass:[Drug class]]);
}
UPDATE
Some logs:
NSLog(@"Class as string: %@", NSStringFromClass([deserializedObject class]));
NSLog(@"Address of the static class: %p", [Drug class]);
NSLog(@"Address of the object class: %p", [deserializedObject class]);
Archiving Headache[1638:60b] Class as string: Drug
Archiving Headache[1638:60b] Address of the static class: 0x8bfd1d0
Archiving Headache[1638:60b] Address of the object class: 0x357c
As you see above the addreses to the class descriptiors are different.