문제

In this gist is JSON data that I use in my UITableView: https://gist.github.com/786829

I take the data marked INPUT and reformat it to OUTPUT such that I can display it acurately with sections in the UITableView. This is done with this code:

groups = [parsedData objectForKey:@"venues"];

NSArray * distinctTypes = [groups valueForKeyPath:@"@distinctUnionOfObjects.type"];

output = [NSMutableArray array];

  for (NSString * type in distinctTypes) {
    NSPredicate * filter = [NSPredicate predicateWithFormat:@"type = %@", type];
    NSMutableDictionary *group = [[NSMutableDictionary alloc] init];
    [group setObject:type forKey:@"type"];

    [group setObject:[groups filteredArrayUsingPredicate:filter] forKey:@"venues"];
    [output addObject:group];
}

Is there a better way to do this? The INPUT is currently used for a sencha app list, that does this grouping automatically.

도움이 되었습니까?

해결책

Are you having a specific problem or just asking about best practices? This looks fine to me, just don't forget to release your group dictionary after you add it to the output array.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top