我有一系列像这样的词组:
{
"album_image" = "BauerOVTDDVD.jpg";
"album_title" = "Zuid-Afrika, Om Van Te Dromen";
"album_year" = 2005;
"track_duration" = xxx;
"track_title" = "Ik Neem Voor Jou De Laatste Trein";
},
{
"album_image" = "BauerOVTDDVD.jpg";
"album_title" = "Zuid-Afrika, Om Van Te Dromen";
"album_year" = 2005;
"track_duration" = xxx;
"track_title" = "Als De Avond Voor Ons Is Gevallen";
},
{
"album_image" = "BauerOVTDDVD.jpg";
"album_title" = "Zuid-Afrika, Om Van Te Dromen";
"album_year" = 2005;
"track_duration" = "3'26";
"track_title" = "'n Handje Vol Geluk";
},
{
"album_image" = "BauerOVTDDVD.jpg";
"album_title" = "Zuid-Afrika, Om Van Te Dromen";
"album_year" = 2005;
"track_duration" = "3'22";
"track_title" = "'n Klein Sterretje";
}
因此每个曲目标题都有不同的track_title。其中一些曲目共享一张专辑。我只想打印独特的专辑封面。这是我必须处理的数据。我应该只用专辑标题创建一个新的词典吗?
答案 0 :(得分:1)
如果您只想要专辑标题,可以使用NSSet。
NSMutableSet *titles = [NSMutableSet alloc] init];
[trackArray enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL *stop) {
[titles addObject:[object objectForKey:@"album_title"]];
}];
[titles release];
答案 1 :(得分:1)
您可以创建一组专辑标题:
NSArray *albumTitlesWithDuplicates = [sourceArray valueForKey:@"album_title"];
NSSet *uniqueAlbumTitles = [NSSet setWithArray:albumTitlesWithDuplicates];