//Dictionary: (keyword value)
Insert code word is too small
Nsarray *array = [Nsarray array];//empty array
Nsdictionary *dictionary = [Nsdictionary dictionary];//empty Dictionary
Nsdictionary *my = [nsdictionary dictionarywithobject:@ "objective" forkey:@ "key"];
NSLog (@ "%@", my);
nsdictionary *to = [nsdictionary dictionarywithobjectsandkeys:@ "123", @ "abc", @ "456", @ "EFG", nil]; //Create a dictionary with multiple values
NSLog (@ "%@", to);
Nsdictionary *me = @{
@ "A": @ "1",
@ "B": @ "2"
};
NSLog (@ "%@,%li", Me,me.count);
NSString *s = [Me objectforkey:@ "a"];//key value corresponding to the object
NSString *ss = me[@ "B"];//is similar to an array
NSLog (@ "%@,%@", ss,s);
Nsarray *keyarr = [me AllKeys];
For (NSString *key in Keyarr)
// {
NSLog (@ "%@ =%@", Key,me[key]);
// }
Nsdictionary *niubi = [nsdictionary dictionarywithobjectsandkeys:@ "Liyuanfang", @ "Direnjie", @ "Moran", @ "Fuermosi", @ " Kenanfushou "@" Kenan ", nil];//create a dictionary with multiple values
Nsarray *keyarr = [Niubi allkeys];//takes all key values in the dictionary
For (NSString *key in Keyarr)
{
NSLog (@ "%@ asked%@ what do you think?" ", Key,niubi[key]);
}
/**********************************************************************************/
Take out all the values in the dictionary
Nsarray *valuearr = [me allvalues];
NSLog (@ "takes the value of all keys in the dictionary%@", Valuearr);
//Dictionary is present, then the developer must think of the convenience of using it
However, there are ways to remove keys or values independently: AllKeys and Allvalues
Because they are array properties, they need to be placed in the newly created array object
An efficient way to iterate through the OC language in the enumerator,
When applied, the general first passes through ..... Enumerator gets the enumerator that is stored in its corresponding type Nsenumerator object
This object will have an automatic down-traversal method Nextobject
Gets the enumerator for key in the dictionary, and then iterates through the enumerator to get the value corresponding to the key
Nsenumerator *e = [me keyenumerator];
ID obj;
while (obj = [E Nextobject]) {
NSLog (@ "%@ =%@", obj,me[obj]);
}
//Get enumerator for value
Nsenumerator *a = [me objectenumerator];
while (obj = [a nextobject])
{
NSLog (@ "%@", obj);
}
//Key and object enumeration block, stop represents traversal stop
[Me enumeratekeysandobjectsusingblock:^ (ID key, id obj, BOOL *stop) {
NSLog (@ "key=%@,value =%@", key,obj);
}];
The Dictionary of Objective-c