The dictionary is unordered and the array is ordered. Dictionaries are divided into: mutable dictionaries and immutable dictionaries
Immutable Dictionary Objects
Nsdictionary * Dict = [[Nsdictionary alloc]initwithobjectsandkeys:@ "one", @ "1", @ "one", @ "2", @ "three", @ "3", @ "four", @ "4 ", nil];
Value = key
Initialization must be one by one the contents of the corresponding dictionary are key-value pairs Key->value content can be arbitrary object pointers
Key is generally nsstring * value can be any object
Cannot appear duplicate key key is unique
Nsdictionary * Dict1 = [nsdictionary dictionarywithdictionary:dict];
Nsarray * values = [Nsarray arraywithobjects:@ "one", @ "one", @ "three", nil];
Nsarray * keys = [Nsarray arraywithobjects:@ "1", @ "2", @ "3", nil];//key-value to correspond
Nsdictionary * Dict2 = [[Nsdictionary alloc]initwithobjects:values Forkeys:keys];
[Dict count]//Key-value pairs must appear in pairs
[Dict objectforkey:@ "5"]//to find the corresponding value according to key
Create an enumerator for key to pass the key element address in the dictionary to the enumerator
Nsenumerator * Enumer1 = [dict keyenumerator];
ID obj;
while (obj = [Enumer1 nextobject]) {
NSLog (@ "%@", [Dict objectforkey:obj]);
}
Create a value enumerator (not used in general, meaningless)
Nsenumerator * Enumer2 = [dict objectenumerator];
while (obj = [Enumer2 nextobject]) {
NSLog (@ "%@", obj);
}
Fast enumeration of enumerations is key (cannot change data, read only)
For (ID key in dict) {
NSLog (@ "%@", key);
}
Nsarray * array = [urlitemdict allvalues];//Get all value
Nsarray * array = [urlitemdict allkeys];//gets all key------variable Dictionary objects
Variable Dictionary objects
Nsmutabledictionary * Dict = [[Nsmutabledictionary alloc]initwithobjectsandkeys:@ "one", @ "1", @ "one", @ "2", @ "three", @ " 3 ", @" four ", @" 4 ", nil];
[Dict setobject:@ "Seven" forkey:@ "7"];//increase key value to key already exists then modify value does not exist add
[Dict setobject:@ "Nine" forkey:@ "1"];//Modify value
[Dict removeobjectforkey:@ "1"];//Delete key value pair