How to find largest value from NSArray
of NSDictionary
?
Here is my code,
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 == %@[email protected]", array];
However this sometimes gives wrong results. Am I missing anything?
Try this way for NSNumber values
NSNumber *max = [array valueForKeyPath:@"@max.data"];
and
NSNumber *max = [array valueForKeyPath:@"@max.data.floatValue"];
for NSString/NSNumbers mixed values.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments