Skip to content

NSKeyedUnarchiver fails to decode NSManagedObject subclass, previously encoded by NSKeyedArchiver #14

@hokster7

Description

@hokster7

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions