Mapping nested IDs with RestKit in Xcode using Objective-C

不羁的心 提交于 2020-01-06 07:48:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!