1

我有这样的映射:

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

RKObjectMapping *objectMapping = [RKEntityMapping mappingForEntityForName:@"Object" inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[objectMapping addAttributeMappingsFromArray:@[ @"content", @"crop", @"fontName", @"fontSize", @"height", @"width",
 @"paddingLeft", @"paddingTop", @"paddingRight", @"paddingBottom", @"src", @"textColor", @"type", @"url", @"posX", @"posY" ]];

[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"objects" toKeyPath:@"objects" withMapping:pageMapping]];

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:pageMapping pathPattern:nil keyPath:@"pages" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];

[[RKObjectManager sharedManager] getObjectsAtPath:[magazine contentPath]
                                       parameters:nil
                                          success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                                              [self sortPageResult];
                                              Page *page = (Page *)[self.pagesFetchedResultController objectAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
                                              NSLog(@"%d", [[page objects] count]);

                                              //[self changeStatusToDownloaded:[magazine magazineID]];
                                              [self.collectionView reloadData];
                                          } failure:^(RKObjectRequestOperation *operation, NSError *error) {
                                              [self displayError];
                                              NSLog(@"Product error: %@", [error localizedDescription]);
                                              [self.collectionView reloadData];
                                          }];

而且我的映射有问题。我清楚地映射“页面”对象,但我无法映射“对象”。当我尝试它时,我得到这样的东西:

Relationship 'objects' fault on managed object (0x1d8b57a0) <Page: 0x1d8b57a0> (entity: Page; id: 0x1d8b0740 <x-coredata://30A44191-D972-4222-88DF-539C2875F293/Page/p1> ; data: {
backgroundColor = FFFFFF;
columns = 0;
content = nil;
header = 1;
link = nil;
magazine = nil;
margin = 0;
objects = "<relationship fault: 0x1d8aea40 'objects'>";
pageID = nil;
rows = 0;
size = 1;
})

谢谢回复!

4

1 回答 1

0

新进展

我改变了:

[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"objects" toKeyPath:@"objects" withMapping:pageMapping]];

反而:

[pageMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"items" toKeyPath:@"items" withMapping:itemMapping]];

现在映射正确,但映射会导致重复的“对象”实体。只有一个对象,一次又一次地重新制作:/

于 2013-04-13T18:58:57.093 回答