• [BS-14] 打印NSArray和NSDictionary的3种方法


    打印NSArray和NSDictionary的3种方法

        NSArray *arr = @[@"奔驰",@"宝马",@"路虎",@"Tesla"];
        //1.直接打印
        NSLog(@"arr:%@",arr);
        //2.使用for...in遍历
        for (NSString *str in arr) {
            NSLog(@"%@",str);
        }
        //3.使用枚举遍历
        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog(@"arr[%lu] = %@",(unsigned long)idx,obj);
        }];
        
        /*打印结果如下:
    
         2016-05-06 23:06:21.876 打印NSArray和NSDictionary[4048:370831] arr:(
         "U5954U9a70",
         "U5b9dU9a6c",
         "U8defU864e",
         Tesla
         )
         
         2016-05-06 23:06:21.877 打印NSArray和NSDictionary[4048:370831] 奔驰
         2016-05-06 23:06:21.877 打印NSArray和NSDictionary[4048:370831] 宝马
         2016-05-06 23:06:21.877 打印NSArray和NSDictionary[4048:370831] 路虎
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] Tesla
         
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] arr[0] = 奔驰
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] arr[1] = 宝马
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] arr[2] = 路虎
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] arr[3] = Tesla
         */
        
        
        NSDictionary *dict = @{@"name":@"Steven",
                               @"sex":@"M",
                               @"age":@26,
                               };
        //1.直接打印
        NSLog(@"dict:%@",dict);
        //2.使用for...in遍历
        for (NSString *key in dict.allKeys) {
            NSLog(@"%@:%@",key,dict[key]);
        }
        //3.使用枚举遍历
        [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            NSLog(@"%@-%@",key,obj);
        }];
    }
    
        /*打印结果如下:
    
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] dict:{
         age = 26;
         name = Steven;
         sex = M;
         }
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] sex:M
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] name:Steven
         2016-05-06 23:06:21.878 打印NSArray和NSDictionary[4048:370831] age:26
         2016-05-06 23:06:21.879 打印NSArray和NSDictionary[4048:370831] sex-M
         2016-05-06 23:06:21.965 打印NSArray和NSDictionary[4048:370831] name-Steven
         2016-05-06 23:06:21.965 打印NSArray和NSDictionary[4048:370831] age-26
         */
    iOS开发者交流群:180080550
  • 相关阅读:
    CNN5 调用 C实现pool2d im2col col2im
    CUDA学习3 Max pooling (python c++ cuda)
    CUDA学习2 基础知识和Julia示例
    CUDA学习1 在Visual Studio和CodeBlocks上配置
    线性搜索
    CNN4 参数优化
    CNN3 im2col
    CNN2 多层卷积
    爬虫:Scrapy8
    爬虫:Scrapy7
  • 原文地址:https://www.cnblogs.com/stevenwuzheng/p/5467433.html
Copyright © 2020-2023  润新知