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

RKManagedObjectImporter crashes while importing when source attribute starts from symbol '@' #1204

Closed
larryonoff opened this issue Feb 1, 2013 · 7 comments
Assignees
Milestone

Comments

@larryonoff
Copy link

RestKit version is (0.20.0pre6).

The following error received: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFDictionary 0x825cc20> valueForUndefinedKey:]: this class is not key value coding-compliant for the key project.'

Crash happens at the class RKMappingOperation in method applyAttributeMappings, code : id value = (attributeMapping.sourceKeyPath == nil) ? self.sourceObject : [self.sourceObject valueForKeyPath:attributeMapping.sourceKeyPath];

There are piece of my code:
[assignmentMapping addAttributeMappingsFromDictionary:@{@"@project": @"projectId"}];

Source attribute is '@project', which starts from the symbol '@'.

Possible solution is described there http://stackoverflow.com/questions/13294696/error-getting-valueforkey-in-an-nsdictionary-for-key-containing-character.

@ghost ghost assigned blakewatters Feb 1, 2013
@blakewatters
Copy link
Member

This is a known limitation and a consequence of RestKit's reliance on Cocoa's key-value coding system for property access. The '@' prefix is reserved for denominating key-value collection operators.

You are going to need to change that JSON format to effectively work with RestKit. Using objectForKey: is a non-starter because it means that you can no longer use key-paths for access to nested properties (i.e. @"user.address.city").

@larryonoff
Copy link
Author

Thank you.

@unlucio
Copy link

unlucio commented May 4, 2013

Hello,
I'm pretty much having the same issue but i cannot change the JSON returned by the API :(
Is there any workaround on this?

If I manually call the service and query the JSON object I get (ie:

 [AFJSONRequestOperation JSONRequestOperationWithRequest:request
            success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { ...

)

I can get those keys with no problems:

[JSON objectForKey:@"@type"]

Since restKit is using AFN as well, I'm not getting why those keys are un-usable :(

thx for help

@unlucio
Copy link

unlucio commented May 6, 2013

I think I kind of came up with a work around in this patch:
#1384

Now restkit is working for me with the @keys :)

@larryonoff
Copy link
Author

Maybe the solution will be to introduce some kind of flag or special prefix symbol or escaping. I really like the idea of collection operators support.

@unlucio
Copy link

unlucio commented May 6, 2013

It still supports those.
The work around simply looks if it can find the dam key with valueForKey or it tries with objectForKey, that's all. No flags needed, too much to know about. Things should work automagically as long as they can :)

@larryonoff
Copy link
Author

Thanks. Then I'm looking forward to the new RestKit release with the improvement.

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

3 participants