数组和字典快速遍历

 

 1 // 方法:
 2 // enumerateObjectsUsingBlock:<#^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)block#>];
 3     
 4 // 使用:
 5     NSArray *array = [NSArray array];
 6     NSDictionary *dictionary = [NSDictionary dictionary];
 7     
 8     [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
 9         NSLog(@"%@", obj);  // obj 数组所有的对象
10         NSLog(@"%ld", idx); // idx 数组所有的下标
11     }];
12     
13     [dictionary enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
14         NSLog(@"%@", key);  // key 字典所有的key
15         NSLog(@"%@", obj);  // obj 字典的所有对象
16     }];
原文地址:https://www.cnblogs.com/crazygeek/p/5500405.html