I need to display a nested array with RestKit, and I almost got it (I think).
JSON I need to map, looks like this
[ { _id: "5058670183970a0002000450", app_store_url: "http://itunes.apple.com/app/culturonda-alto-adige-sudtirol/id534467629", comments: [ { _id: "5058670783970a0002000456", }, { _id: "50588d7f83970a000200065c", } ] } ]
My controllers for storing information are as follows:
and
My mapping is as follows:
RKObjectManager *objectManager = [RKObjectManager sharedManager]; RKObjectMapping *commentsMapping = [RKObjectMapping mappingForClass:[CommentData class]]; [commentsMapping mapKeyPathsToAttributes:@"_id", @"commentId", nil]; RKObjectMapping *designMapping = [RKObjectMapping mappingForClass:[DesignData class] ]; [designMapping mapKeyPathsToAttributes:@"_id", @"designId", nil]; [designMapping mapKeyPath:@"comments" toRelationship:@"commentsRelationship" withMapping:commentsMapping]; [objectManager.mappingProvider setMapping:designMapping forKeyPath:@""];
Comments fall into the array, but are not stored in the comment controller. If I show the comments in the objecloader callback as follows:
DesignData *designData = [objects objectAtIndex:0]; NSLog(@"Loaded %@ ", designData.commentsRelationship);
this gives me:
2012-10-20 22:37:55.258 RestKitTest5[4144:c07] Loaded {( <CommentData: 0x8689730>, <CommentData: 0x868bed0>, <CommentData: 0x868bfe0>, <CommentData: 0x868bf50> )}
This is the beginning. But I can not:
DesignData *designData = [objects objectAtIndex:0]; NSLog(@"Loaded %@ ", designData.commentsRelationship.commentId);
So how can I store all this as an array?