AutoCoding icon indicating copy to clipboard operation
AutoCoding copied to clipboard

NSKeyedUnarchiver fails to decode NSManagedObject subclass, previously encoded by NSKeyedArchiver

Open hokster7 opened this issue 11 years ago • 1 comments

Specific Error

MESContinent is a NSManagedObject subclass. It has a String field called name.

[<MESContinent 0x9be07f0> setValue:forUndefinedKey:]: the entity (null) is not key value coding-compliant for the key "name".
(
    0   CoreFoundation                      0x01bff5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x019828b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01c8f6a1 -[NSException raise] + 17
    3   CoreData                            0x002514c4 -[NSManagedObject setValue:forUndefinedKey:] + 340
    4   Foundation                          0x015aff3b _NSSetUsingKeyValueSetter + 88
    5   CoreData                            0x001dbe28 -[NSManagedObject setValue:forKey:] + 120
    6   BDDReactiveCocoa                    0x0000bb47 -[NSObject(AutoCoding) setWithCoder:] + 919
    7   BDDReactiveCocoa                    0x0000bc4b -[NSObject(AutoCoding) initWithCoder:] + 59
    8   Foundation                          0x01595d6a _decodeObjectBinary + 3498
    9   Foundation                          0x01594e55 _decodeObject + 340
    10  Foundation                          0x01594cf9 -[NSKeyedUnarchiver decodeObjectForKey:] + 181
    11  Foundation                          0x016068cd +[NSKeyedUnarchiver unarchiveObjectWithData:] + 106

Reproduction

As a part of further investigation into #13, I wrote a failing test that doesn't use HRCoder. Please run it:

git clone https://github.com/fatuhoku/autocoding-demo
pod install
open BDDReactiveCocoa.xcworkspace

... and then run the BDDReactiveCocoaSpecs target on an iPad Simulator.

If you look in BDDReactiveCocoaSpecs/BDDObjectModelSpecs.m, you can see that I'm trying to just encode and decode an NSManagedObject subclass to and from NSData.

NSData *outgoingData = [NSKeyedArchiver archivedDataWithRootObject:europe];
// Pretend that we've stored it somewhere and we're now retrieving it
NSData *incomingData = outgoingData;
MESContinent *incomingEurope = [NSKeyedUnarchiver unarchiveObjectWithData:incomingData]; // Fails on this line.

hokster7 avatar Mar 28 '14 17:03 hokster7

potentially related: https://github.com/nicklockwood/FastCoding/issues/3

I'm sure there's a lot of similar code amongst these libraries and this looks awfully similar to what I just reported hopefully it's a small tweak that handles it on both sides

mrtristan avatar Apr 03 '14 03:04 mrtristan