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