如何在NSMutableDictionary中找到密钥的最大长度?

时间:2014-12-27 18:05:26

标签: objective-c

我的字典看起来像这样

@{@"Blue": @"Big", 
@"Red": @"medium",
@"Yellow": @"small"}

我想知道最高密钥长度是6,因为黄色是最长密钥

1 个答案:

答案 0 :(得分:3)

你可以试试这个。假设a是你的字典。您可以在此处找到来源:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/CollectionOperators.html

NSArray *array = a.allKeys;
NSNumber* maxLength= [array valueForKeyPath:@"@max.length"];
NSLog(@"Longest is %lu",maxLength.integerValue);