我有一个NSDictionary,其中每个值是另一个带有3个键的NSDictionary: @" URL",@" DATE"和@" META"。
我需要有效地检索@" DATE"使用@" URL"的字典值key等于特定的NSURL。
任何帮助?
答案 0 :(得分:0)
尝试了解KVC:http://nshipster.com/kvc-collection-operators/
实施例: https://gist.github.com/TonnyXu/3447781
修改强>
正如 Nick Lockwood 所述:http://iosdevelopertips.com/objective-c/high-performance-collection-looping-objective-c.html
枚举NSDictionary时
- 大部分时间使用[dictionary enumerateKeysAndObjectsUsingBlock:]。
- 如果您需要修改字典,请使用([字典allKeys]中的id键)。
- 如果您的代码可能会受益于并行执行,请尝试[dictionary enumerateKeysAndObjectWithOptions:usingBlock:]。
答案 1 :(得分:0)
使用NSDictionary方法
enumerateKeysAndObjectsUsingBlock:
或
keysOfEntriesPassingTest:
了解如何使用块对于任何iOS编程都非常有价值。
答案 2 :(得分:0)
使用如下的NSPredicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"URL == %@", aURL];
然后使用NSDictionary的allValues方法获取值的NSArray。之后,将谓词应用于NSArray。
NSArray * arrays = [[dic allValues] filteredArrayUsingPredicate:predicate];