Restkit手动映射:选择托管对象上下文

时间:2013-07-11 10:02:28

标签: mapping restkit manual managedobjectcontext

我已成功地使用托管对象成功手动映射json字符串,但我无法找到如何将结果对象插入到我选择的托管对象上下文中。 我是否必须创建一个RKObjectManager实例才能做到这一点?

NSMutableDictionary *area = [NSMutableDictionary dictionaryWithObject:dictionary forKey:@"restricted_position_detail"];
NSString* JSONString = [[DataProviderManager sharedManager] getJsonStringFromObject:area];
NSString* MIMEType = @"application/json";
NSError* error = nil;
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:MIMEType];
id parsedData = [parser objectFromString:JSONString error:&error];
if (parsedData == nil && error) {
    DLog(@"%@",error);
}

RKObjectMappingProvider* mappingProvider = [RKObjectManager sharedManager].mappingProvider;
[mappingProvider setMapping:[self getObjectMapping] forKeyPath:@"restricted_position_detail"];
RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:parsedData mappingProvider:mappingProvider];
RKObjectMappingResult* result = [mapper performMapping];
if (result) {
    DLog(@"Yay! Mapping finished successfully");
}
else{
    DLog(@"Yay! Mapping failed");
}

1 个答案:

答案 0 :(得分:0)

最后我要做的就是将RKObjectMapper实例targetObject属性设置为在好moc中创建的对象!