Skip to content

Instantly share code, notes, and snippets.

@chrismanderson
Created December 2, 2012 18:16
Show Gist options
  • Save chrismanderson/4190263 to your computer and use it in GitHub Desktop.
Save chrismanderson/4190263 to your computer and use it in GitHub Desktop.
I'm using RestKit 0.10.2.
I have the following JSON data:
{
"title":"2012 General Election: Romney vs. Obama",
"last_updated":"2012-01-02T17:08:44Z",
"estimates":[
{ "choice":"Romney", "value":44.5 },
{ "choice":"Obama", "value":46.6 }
],
"estimates_by_date":[
{ "date":"2012-06-28",
"estimates":[
{ "choice":"Romney", "value":44.5 },
{ "choice":"Obama", "value":46.6 }
]
},
{ "date":"2012-06-27",
"estimates":[
{ "choice":"Romney", "value":44.5 },
{ "choice":"Obama", "value":46.5 }
]
}
]
}
I currently have a `Chart` class and an `Estimate` class. I've correctly set up the mappings to load the `estimates` attribute on `Chart` with an array of `Estimate` objects.
RKObjectMapping *estimateMapping = [RKObjectMapping mappingForClass:[Estimate class]];
[estimateMapping mapAttributes:@"value", @"choice", nil];
RKObjectMapping *chartMapping = [RKObjectMapping mappingForClass:[Chart class]];
[chartMapping mapAttributes:@"title", @"last_updated", nil];
[chartMapping mapKeyPath:@"estimates" toRelationship:@"estimates" withMapping:estimateMapping];
However, there are also `estimates_by_date`.
How can I load the array of `estimates_by_date` into an `NSDictionary` on `Chart` where the `date` is the key and an `Estimate` object is the value?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment