基于块的枚举

枚举词典允许你使用方法 enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block 在每个字典键值对上运行代码块

例:

NSDictionary stockSymbolsDictionary = @{
                                         @"AAPL": @"Apple",
                                         @"GOOGL": @"Alphabet",
                                         @"MSFT": @"Microsoft",
                                         @"AMZN": @"Amazon"
                                       };
NSLog(@"Printing contents of dictionary via enumeration");
[stockSymbolsDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
    NSLog(@"Key: %@, Value: %@", key, obj);
}];