问题
I've got a webservice returning me a JSON formatted string looking like this :
{"id":4,
"name":"name",
"image":1,
"contacts":[2,3]
}
Where the contacts array contains primary key to other objects. I tried doing my mapping in this way :
RKManagedObjectMapping* mapping = [RKManagedObjectMapping mappingForClass:[OETGroup class] inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
[mapping mapKeyPath:@"id" toAttribute:@"identifiant"];
[mapping mapKeyPath:@"name" toAttribute:@"name"];
[mapping mapKeyPath:@"image" toAttribute:@"image"];
RKManagedObjectMapping* contactSimpleMapping = [RKManagedObjectMapping mappingForClass:[OETContact class] inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
[contactSimpleMapping mapKeyPath:@"" toAttribute:@"identifiant"];
[mapping mapKeyPath:@"contacts" toRelationship:@"contacts" withMapping:contactSimpleMapping];
[mapping connectRelationship:@"contacts" withObjectForPrimaryKeyAttribute:@"contacts"];
[mapping setPrimaryKeyAttribute:@"identifiant"];
But every time I run this code, I bump into this exception :
this class is not key value coding-compliant for the key .'
Any idea why?
来源:https://stackoverflow.com/questions/14260806/mapping-nested-ids-with-restkit-in-xcode-using-objective-c