分组并组合NSMutableArray

时间:2013-09-16 10:39:27

标签: ios objective-c uitableview nsmutablearray

我有一个名为matches的NSMutableArray,其中包含其他名为games的对象。游戏是games.title,games.players,games.dates。

的集合

我的代码如下;

 for (int i=0; i<json.count; i++)
 {
        games = [[Games alloc] init];
        games.title= [[json objectAtIndex:i] objectForKey:@"titleJson"];
        games.date= [[json objectAtIndex:i] objectForKey:@"dateJson"];
        NSString *players=[[json objectAtIndex:i] objectForKey:@"playersJson"];
        arrayPlayers= [[NSMutableArray alloc] initWithObjects:playersJson, nil];
        play.players=players;        
        [matches addobject: games]
  }

我能够在uitableview以及玩家的详细视图上打印这个,但是有重复的值,例如

[Match 1, May 2013, striker 1]
[Match 1, May 2014, striker 2]
[Match 2, May 2014, striker 1]

如何组合匹配1,以便我可以获得此结果;

[Match 1, May 2013, May2014, striker 1, sticker 2]
[Match 2, May 2014, striker 1]

1 个答案:

答案 0 :(得分:0)

使用key-value programming guide

NSArray *distictResult = [matches valueForKeyPath:@"@distinctUnionOfObjects.games.title"];