我有这样的映射:
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;
})
谢谢回复!