Mapping nested IDs with RestKit in Xcode using Obj

2019-09-09 05:59发布

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?

0条回答
登录 后发表回答