I have an app that allows you to rate media 0-5 stars as integers using Core Data. I have the aggregate fetch request using propertiesToGroupBy to return a count of each media type and rating. The print() result of the request is
[
["rating": 0, "count": 17, "type": movie],
["count": 10, "rating": 0, "type": show],
["count": 8, "type": movie, "rating": 1],
["rating": 2, "count": 36, "type": movie],
["rating": 2, "count": 15, "type": show],
["type": movie, "count": 161, "rating": 3],
["rating": 3, "type": show, "count": 26],
["rating": 4, "count": 217, "type": movie],
["count": 48, "rating": 4, "type": show],
["type": movie, "rating": 5, "count": 114],
["count": 63, "rating": 5, "type": show],
["count": 8, "rating": 4, "type": web]
]
returned as an NSDictionary/dictionaryResultType. I would like to transform this result into separate integer arrays for each type, with the count for each rating 5-0, even if there is no result for the combination of type and rating. Something like:
ratings = [5, 4, 3, 2, 1, 0]
and then
movie = [114, 217, 161, 36, 8, 17]
show = [63, 48, 26, 15, 0, 10]
web = [0, 8, 0, 0, 0, 0]
Is there an efficient way to do this, like with mapping or grouped dictionaries?