1

RESTKIT 0.20 を使用していますが、マッピングに問題があります。誰がエラーがどこにあるのか教えてもらえますか? Thxと私のコードがあります:

RKObjectMapping* pageMapping = [RKEntityMapping mappingForEntityForName:@"Page" inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[pageMapping addAttributeMappingsFromArray:@[ @"rows", @"columns" ]];


RKObjectMapping* magazineMapping = [RKEntityMapping mappingForEntityForName:@"Magazine" inManagedObjectStore:[RKManagedObjectStore defaultStore]];

[magazineMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"pages"
                                                                               toKeyPath:@"pages"
                                                                             withMapping:pageMapping]];


RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:magazineMapping pathPattern:nil keyPath:@"magazine" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", kBasePath, [magazine contentPath]]];
NSURLRequest *r = [NSURLRequest requestWithURL:URL];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:r responseDescriptors:@[ responseDescriptor ]];

[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    RKLogInfo(@"Load collection of Articles: %@", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    RKLogError(@"Operation failed with error: %@", error);
}];

[objectRequestOperation start];

エンティティ マガジンがあります。

@interface Magazine : NSManagedObject

@property (strong) NSString * contentPath;
@property (strong) NSDate * date;
@property (strong) NSString * icon;
@property (strong) NSString * magazineID;
@property (strong) NSDecimalNumber * price;
@property (strong) id priceLocale;
@property (strong) NSString * title;
@property (strong) Page *pages;

そして最後に Page エンティティがあります:

@class Magazine;

@interface Page : NSManagedObject

@property (strong) NSString * content;
@property (strong) NSNumber * contentID;
@property (strong) NSNumber * columns;
@property (strong) NSNumber * rows;
@property (strong) NSString *pageID;
@property (strong) Magazine *assignedMagazine;

他の「ダウンロード」メソッドには問題がないため、エラーは Page エンティティのマッピングにあるはずです。

4

1 に答える 1

1

次のようにマッピングを使用します。

RKManagedObjectMapping *mappingPage = [RKManagedObjectMapping mappingForClass:[Page class] inManagedObjectStore:self.objectStore];
    mappingPage.setDefaultValueForMissingAttributes = NO;
    mappingPage.primaryKeyAttribute = @"contentID";
    [mappingPage mapKeyPathsToAttributes:

     @"CONTENT_FROM_WEBSERVICE", @"content",
     @"ID_FROM_WEBSERVICE", @"contentID",
     @"COLUMNS_FROM_WEBSERVICE", @"columns",
     @"ROWS_FROM_WEBSERVICE", @"rows",     
     nil];
于 2013-04-11T07:11:28.160 に答える