0

I have an iOS app that is using Restkit to pull info from a server. I have reached a point where I am using more than one CoreData Entity. I have set up an new entity mapping for restkit but my response from the server results in no mappable values because it is using the wrong entity mapping. Can someone clue me in on how to tell it which one to use.

Here are the two mappers:

RKEntityMapping *articleEntityMapping = [RKEntityMapping mappingForEntityForName:@"Gist" inManagedObjectStore:managedObjectStore];
[entityMapping addAttributeMappingsFromDictionary:@{
 @"id.text":             @"gistID",
 @"title.text":          @"title",
 @"hashtags.text":       @"hashtags",
 @"imageUrl.text":       @"imageUrl",
 @"description.text":    @"summary",
 @"copy.text":           @"fullArticle",
 @"articleId.text":      @"articleId"}];
entityMapping.identificationAttributes = @[ @"gistID" ];

RKEntityMapping *userEntityMapping = [RKEntityMapping mappingForEntityForName:@"UserInfo" inManagedObjectStore:managedObjectStore];
[userEntityMapping addAttributeMappingsFromDictionary:@{
 @"firstName.text":      @"firstName",
 @"lastName.text":       @"lastName",
 @"birthDay.text":       @"birthDay",
 @"birthMonth.text":     @"birthMonth",
 @"birthYear.text":      @"birthYear"}];
userEntityMapping.identificationAttributes = @[ @"birthDay" ];

I thought the identificationAttributes gave it the cue but it didn't seem to work. There is no relationship between these two entities. They come from completely unrelated API's on the server side.

Here is what I am using to make the request that uses articleEntityMapping

[[RKObjectManager sharedManager] postObject:nil path:@"/rest/search?ip=255.255.255.0" parameters:search success:nil failure:nil];

Here is what I am using to make the request that userEntityMapping should use but doesn't.

[[RKObjectManager sharedManager] postObject:nil path:@"/rest/person/login?ip=255.255.255.0" parameters:postBody success:nil failure:nil];
4

1 回答 1

0

您的映射只是故事的一半,另一半是响应描述符。虽然映射告诉 RestKit 如何转换接收到的数据,但响应描述符告诉 RestKit 何时适合使用映射。这是通过路径模式和关键路径参数的组合来完成的。路径模式与用于获取数据的 URL 匹配,因此您需要设置它。

于 2013-07-09T06:57:33.993 回答