restkit将相同的响应映射到不同的类

时间:2013-01-05 08:36:08

标签: ios core-data mapping restkit

我正在尝试做的是对两个不同的类进行相同的响应,它们是一个NSManagedObject。所以我拥有的是:

RKObjectMapping *movellasMapping = [RKObjectMapping mappingForClass:[Movella class]];
[movellasMapping addAttributeMappingsFromDictionary:@{
 @"numfavourites" : @"numfavourites",
 @"numcomments" : @"numcomments",
 @"id" : @"id",
 @"title" : @"title",
 @"cover" : @"cover",
 @"synopsis" : @"synopsis",
 @"numviews" : @"numviews",
 @"numlikes" : @"numlikes",
 }];

RKRelationshipMapping* relationShipMappingForMovella = [RKRelationshipMapping relationshipMappingFromKeyPath:@"author"
                                                                                                               toKeyPath:@"author"
                                                                                                             withMapping:userSimpleMapping];
[movellasMapping addPropertyMapping:relationShipMappingForMovella];

//Core Data
RKEntityMapping *movellasCDMapping = [RKEntityMapping mappingForEntityForName:@"MovellaCD" inManagedObjectStore:managedObjectStore];
movellasCDMapping.identificationAttributes = @[ @"id" ];

[movellasCDMapping addAttributeMappingsFromArray:@[ @"title", @"id", @"cover", @"chapters" ]];

RKResponseDescriptor *responseDescriptorForMovellas2 = [RKResponseDescriptor responseDescriptorWithMapping:movellasMapping pathPattern:@"movella/:id/"
                                                                                                                  keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]];

RKResponseDescriptor *responseDescriptorForMovellasCD = [RKResponseDescriptor responseDescriptorWithMapping:movellasCDMapping pathPattern:@"movella/:id/"
                                                                                                       keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]];

NSManagedObject类是:

@interface MovellaCD : NSManagedObject

@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * id;
@property (nonatomic, retain) NSString * cover;
@property (nonatomic, retain) ChapterCD *chapters;
@end

和NSObject类是:

@interface Movella : NSObject

@property (nonatomic, strong) NSArray* chapters;
@property (nonatomic, strong) NSNumber* pubdate;
@property (nonatomic, strong) NSNumber* numfavourites;
@property (nonatomic, strong) NSNumber* updateddate;
@property (nonatomic, strong) NSNumber* numcomments;
@property (nonatomic, strong) NSString* lang;
@property (nonatomic, strong) NSString* id;
@property (nonatomic, strong) UserSimple* author;
@property (nonatomic, strong) NSString* category;
@property (nonatomic, strong) NSString* title;
@property (nonatomic, strong) NSString* cover;
@property (nonatomic, strong) NSNumber* numwords;
@property (nonatomic, strong) NSString* synopsis;
@property (nonatomic, strong) NSString* rating;
@property (nonatomic, strong) NSNumber* numviews;
@property (nonatomic, strong) NSNumber* numlikes;

@end

正如您所看到的,属性不同,即使响应相同也是我收到此错误的原因[MovellaCD作者]:无法识别的选择器发送到实例0x96a3180

属性不同,因为这是我的核心数据模型所需要的全部内容。 任何帮助都会受到很多赞扬。谢谢

0 个答案:

没有答案