Domanda

In questo succo è dati JSON che uso nel mio UITableView: https://gist.github.com/786829

prendo dei dati contrassegnati INPUT e riformattare a produzione tali che posso visualizzarlo acurately con sezioni del UITableView. Questo viene fatto con questo codice:

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];
}

C'è un modo migliore per fare questo? L'ingresso è attualmente utilizzato per un elenco sencha app, che fa questo raggruppamento automaticamente.

È stato utile?

Soluzione

Stai avendo un problema specifico o semplicemente chiedendo circa le migliori pratiche? Questo sembra bene a me, proprio non dimenticate di rilasciare il dizionario group dopo aver aggiunto alla matrice di output.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top