Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with : class is not key value coding-compliant for the key(s): -hash or -debugDescription or -description #39

Open
greinaldor opened this issue Sep 29, 2015 · 3 comments

Comments

@greinaldor
Copy link

I use an instance of ObjectMapper and then configure it by adding an InCodeMappingProvider as the mappingProvider. For example :

self.mapper_ = [[ObjectMapper alloc] init];
InCodeMappingProvider *inCodeProvider = [[InCodeMappingProvider alloc] init];
[self.mapper setMappingProvider:inCodeProvider];

I have a user object like this :

@interface SSUserStats : SSObject <SSObjectMapping>

@property (nonatomic, strong, nullable) NSNumber * storeCount;
@property (nonatomic, strong, nullable) NSNumber * followerCount;
@property (nonatomic, strong, nullable) NSNumber * followeeCount;

@end

@interface SSUser : NSObject <ObjectMapping>

@property (nonatomic, strong, nullable) NSString  *userId;
@property (nonatomic, strong, nullable) NSString  *email;
@property (nonatomic, strong, nullable) NSString  *username;
@property (nonatomic, strong, nullable) NSString  *firstName;

@property (nonatomic, strong, nullable) UserStats *stats;

@property (nonatomic, strong, nullable) NSString  *profileImageFilename;
@property (nonatomic, strong, nullable) NSString  *headerImageFilename;

@end

When then I try to create a dictionary from a user object and then convert back this dictionary to an object my app crash :

SSUserStats *stats = [[SSUserStats alloc] init];
stats.storeCount = @(42);
stats.followeeCount = @(12);
stats.followerCount = @(21);

SSUser  *user = [[SSUser alloc] init];
user.firstName = @"Adrien";
user.email = @"[email protected]";
user.username = @"flop";
user.stats = stats;

NSDictionary *dict = [self.mapper dictionaryFromObject:user];
NSLog(@"Dic : %@", dict);
User *user2 = [self.mapper objectFromSource:dict toInstanceOfClass:[User class]];
NSLog(@"User2 : %@", [user2 description]);

First log shows :

Dic : {
    debugDescription = "<User: 0x7fa183e0cd20>";
    description = "<User: 0x7fa183e0cd20>";
    firstName = Adrien;
    email = @"[email protected]";;
    hash = 140331679010080;
    stats =     {
        debugDescription = "<UserStats: 0x7fa183e2dde0>";
        description = "<UserStats: 0x7fa183e2dde0>";
        followeeCount = 12;
        followerCount = 21;
        hash = 140331679145440;
        storeCount = 42;
        superclass =         {
        };
    };
    superclass = NSObject;
}

At the third line, my program crash with :

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<User 0x7fa183f22360> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key hash.'

I'm using Xcode 7, iOS 9. It's really sad because I really like this lib and the way it's architectured. My question is why : hash / superclass / debugDescription / description are processed which leads to this crash, Any idea of how I can fix this. Many thanks.

@greinaldor greinaldor changed the title Crash with : class is not key value compliant with key: -hash or -debugDescription or -description Crash with : class is not key value coding-compliant for the key(s): -hash or -debugDescription or -description Sep 29, 2015
@aryaxt
Copy link
Owner

aryaxt commented Sep 29, 2015

I'm updating my code to swift 2.0 and Xcode 7 this weekend, will fix it and release a new version before Monday if the fix is simple

@greinaldor
Copy link
Author

Wow nice, this would be really good ;) Keep going the good work.

@aryaxt
Copy link
Owner

aryaxt commented Oct 4, 2015

I'm having a problem reproducing this issue.
can you create a failing unit test using the models I have in the project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants