1

我要做的是将相同的响应映射到两个不同的类,其中一个是 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 author]: unrecognized selector sent to instance 0x96a3180

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

4

0 回答 0