1//Initialize an empty dictionary
2//nsdictionary *dictionary = [[Nsdictionary alloc] init];
3//Initialize an empty code
4//nsdictionary *dictionary1 = [Nsdictionary dictionary];
5//add a pair of key values while initializing
6//Nsdictionary *dictionary2 = [nsdictionary dictionarywithobject:@ "value" forkey:@ "key"];
7//adding many pairs of key values while initializing
8//the preceding value can be any type
9//followed by a key must be a string
TenNsdictionary *dictionary3 = [Nsdictionary Dictionarywithobjectsandkeys:@"Object",@"Key",@"Object1",@"Key1",@"Object2",@"Key2", nil];
One//a new Way of dictionary
A//preceded by a key is a value opposite to the key value of the previous method
-Nsdictionary *dictionary4 = @{@"Key":@"value",@"Key1":@"value 1"};
-NSLog (@"%@", Dictionary3);
theNSLog (@"%@", Dictionary4);
-
- //Objectforkey: Through the value of the key curvature dictionary
-NSLog (@"%@", [Dictionary4 Objectforkey:@"Key"]);
+//The second way of taking value
-NSLog (@"%@", dictionary4[@"Key1"]);
+
A
at//1 Use a dictionary to express your test scores Chinese 25 math 1000 English 3
-
-Nsdictionary *scrose = [Nsdictionary Dictionarywithobjectsandkeys:@" -",@"Chinese",@" +",@"Math",@"3",@"中文版", nil];
-[Scrose Objectforkey:@"Chinese"];
-[Scrose Objectforkey:@"Math"];
-[Scrose Objectforkey:@"Chinese version"];
inNSLog (@"%@ %@ %@", [Scrose Objectforkey:@"Chinese"],[scrose Objectforkey:@"Math"],[scrose Objectforkey:@"中文版"]);
-Nsdictionary *year = [Nsdictionary Dictionarywithobjectsandkeys:@"Germination",@"Spring",@"Flowering",@"Xia",@"Results",@"Autumn",@"Fade",@"Winter",@"Germination 1",@"Spring 1",@"Flowering 1",@"Summer 1",@"Results 1",@"Autumn 1",@"Fade 1",@"Winter 1", nil];
to//outputs a value corresponding to a key
+NSLog (@"%@", [Year objectforkey:year.allkeys[0]]);
-//Traverse all the key values
the//AllKeys is an array of all keys
*//count gets how many elements are in the number
$ for(NSString *keyinchYear.allkeys) {
Panax NotoginsengNSLog (@"%@ %@", Key,[year Objectforkey:key]);
-}
the
+
ANSLog (@"%@ %@ %@ %@", [Year Objectforkey:@"Spring"],[year Objectforkey:@"Xia"],[year Objectforkey:@"Autumn"],[year Objectforkey:@"Winter"]);
the
Execution Result:
Objective-c Dictionary