[BS-14] 3 ways to print Nsarray and nsdictionary

Source: Internet
Author: User

3 Ways to print Nsarray and nsdictionary

Nsarray *arr = @[@"Mercedes",@"BMW",@"Land Rover",@"Tesla"]; //1. Direct PrintingNSLog (@"arr:%@", arr); //2. Using for...in traversal     for(NSString *strincharr) {NSLog (@"%@", str); }    //3. Using enumeration traversal[Arr enumerateobjectsusingblock:^ (ID_nonnull obj, Nsuinteger idx, BOOL *_nonnull stop) {NSLog (@"Arr[%lu] =%@", (unsignedLong) idx,obj);        }]; /*the results are printed as follows: 2016-05-06 23:06:21.876 print Nsarray and nsdictionary[4048:370831] Arr: ( "\u5954\u9a70", "\u5b9d\u9a6c", "\u8def\u864e", Tesla) 2016-05-06 23:06:21.877 print Nsarray and Nsdicti ONARY[4048:370831] Mercedes 2016-05-06 23:06:21.877 print Nsarray and nsdictionary[4048:370831] BMW 2016-05-06 23:06:21.877 Print NSA Rray and nsdictionary[4048:370831] Land Rover 2016-05-06 23:06:21.878 print Nsarray and nsdictionary[4048:370831] Tesla 2016-05-0 6 23:06:21.878 print Nsarray and nsdictionary[4048:370831] arr[0] = Mercedes 2016-05-06 23:06:21.878 print Nsarray and nsdictionary[4048:370 831] arr[1] = BMW 2016-05-06 23:06:21.878 printing nsarray and nsdictionary[4048:370831] arr[2] = Land Rover 2016-05-06 23:06:21.878 hit India Nsarray and nsdictionary[4048:370831] arr[3] = Tesla*/nsdictionary*dict = @{@"name":@"Steven",                           @"Sex":@"M",                           @" Age":@ -,                           }; //1. Direct PrintingNSLog (@"dict:%@", Dict); //2. Using for...in traversal     for(NSString *keyinchDict.allkeys) {NSLog (@"%@:%@", Key,dict[key]); }    //3. Using enumeration traversal[Dict enumeratekeysandobjectsusingblock:^ (ID_nonnull Key,ID_nonnull obj, BOOL *_nonnull stop) {NSLog (@"%@-%@", Key,obj);    }];} /*the results are printed as follows: 2016-05-06 23:06:21.878 print Nsarray and nsdictionary[4048:370831] dict:{age = 26;     name = Steven;     sex = M; } 2016-05-06 23:06:21.878 print Nsarray and nsdictionary[4048:370831] sex:m 2016-05-06 23:06:21.878 print Nsarray and nsdictionary [4048:370831] Name:steven 2016-05-06 23:06:21.878 print Nsarray and nsdictionary[4048:370831] age:26 2016-05-06 23:06:21.8     79 printing Nsarray and nsdictionary[4048:370831] sex-m 2016-05-06 23:06:21.965 print Nsarray and nsdictionary[4048:370831] Name-Steven 2016-05-06 23:06:21.965 print Nsarray and nsdictionary[4048:370831] age-26*/

[BS-14] 3 ways to print Nsarray and nsdictionary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.