Ответ 1
Просто используйте следующий код для удаления значений дубликатов.
your_array = [self groupsWithDuplicatesRemoved:(NSArray *)your_array myKeyParameter:@"your_key_name"];
Вам нужно просто вызвать groupsWithDuplicatesRemoved
этот метод с именем ключа.
- (NSMutableArray *) groupsWithDuplicatesRemoved:(NSArray *) groups myKeyParameter:(NSString *)myKeyParameter {
NSMutableArray * groupsFiltered = [[NSMutableArray alloc] init]; //This will be the array of groups you need
NSMutableArray * groupNamesEncountered = [[NSMutableArray alloc] init]; //This is an array of group names seen so far
NSString * name; //Preallocation of group name
for (NSDictionary * group in groups) { //Iterate through all groups
name = [NSString stringWithFormat:@"%@", [group objectForKey:myKeyParameter]]; //Get the group name
if ([groupNamesEncountered indexOfObject: name]==NSNotFound) { //Check if this group name hasn't been encountered before
[groupNamesEncountered addObject:name]; //Now you've encountered it, so add it to the list of encountered names
[groupsFiltered addObject:group]; //And add the group to the list, as this is the first time it encountered
}
}
return groupsFiltered;
}
Надеюсь, это то, что вы ищете. Меня волнует любая забота.:)