如何从NSDictionary对象数组中找到最大值?

Sac*_*ram 2 objective-c nsarray ios

如何找到最大的价值NSArrayNSDictionary

这是我的代码,

NSDictionary *d1 = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:35] forKey:@"data"];
NSDictionary *d2 = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:52] forKey:@"data"];

NSArray *array = [NSArray arrayWithObjects:d1, d2, nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.data == %@.@max.data", array];
Run Code Online (Sandbox Code Playgroud)

然而,这有时会产生错误的结果 我错过了什么吗?

mal*_*lex 9

对NSNumber值尝试这种方式

NSNumber *max = [array valueForKeyPath:@"@max.data"];
Run Code Online (Sandbox Code Playgroud)

NSNumber *max = [array valueForKeyPath:@"@max.data.floatValue"];
Run Code Online (Sandbox Code Playgroud)

对于NSString/NSNumbers混合值.