1

私がやろうとしているのは、同じ応答を 2 つの異なるクラスにマップすることです。そのうちの 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 作成者]: 認識されないセレクターがインスタンス 0x96a3180 に送信されました

Core Data モデルに必要なのはそれだけであるため、プロパティは異なります。どんな助けでも大歓迎です。ありがとうございました

4

0 に答える 0