数组和字典快速遍历

 

 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     }];

 

posted @ 2016-05-17 21:41  Leo-Wmw  阅读(539)  评论(0编辑  收藏  举报