我试图通过使用 NSPredicate 来获得以下目标值。
但是,我在使用 NSPredicate 语法时遇到了困难。
我想获取源数据中同名的最大年龄的姓氏列表而不会重复。
请任何人的帮助...
NSDictionary *dic1 = [NSDictionary dictionaryWithObjects:@[@"James", @10] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic2 = [NSDictionary dictionaryWithObjects:@[@"Robert", @15] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic3 = [NSDictionary dictionaryWithObjects:@[@"Robert", @10] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic4 = [NSDictionary dictionaryWithObjects:@[@"James", @20] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic5 = [NSDictionary dictionaryWithObjects:@[@"David", @20] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic6 = [NSDictionary dictionaryWithObjects:@[@"Walter", @30] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic7 = [NSDictionary dictionaryWithObjects:@[@"Nicholas", @30] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic8 = [NSDictionary dictionaryWithObjects:@[@"David", @30] forKeys:@[@"LastName", @"Age"]];
NSDictionary *dic9 = [NSDictionary dictionaryWithObjects:@[@"David", @30] forKeys:@[@"LastName", @"Age"]];
NSArray *persons = [NSArray arrayWithObjects:dic1, dic2, dic3, dic4, dic5, dic6, dic7, dic8, dic9, nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:???]
NSArray *result = [persons filteredArrayUsingPredicate:predicate];
NSLog(@"result : %@",result);
source data
LastName age
James 10
Robert 15
Robert 10
James 20
David 20
Walter 30
Nicholas 30
David 30
David 30
target data
James 20
Robert 15
David 30
Walter 30
Nicholas 30