The dictionary NSDictionary in OC and the dictionary nsdictionary in oc
======================================
Dictionary
======================================
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: @ "One", @ "1", @ "Two", @ "2", @ "Three ", @ "3", @ "One", @ "4", nil];
// The data in the dictionary is stored as a key-value pair.
// @ "One" and @ "1" form a key-Value Pair
// @ "1" is called a key)
// @ "One" is called a value)
// The value is the data to be stored, and the key is the index of the data to be searched.
// The function of the dictionary is to quickly find the value through the key.
// The value can be repeated and the key is unique.
// The key-value pairs in the dictionary are not ordered. There is no so-called first key-value pair, and the second key-Value Pair
// Keys and values are all arbitrary objects, and the address of the objects stored in the dictionary. However, keys often use strings.
NSDictionary * dict2 =@ {@ "4": @ "Four", @ "1": @ "One", @ "2": @ "Two ", @ "3": @ "Three "};
NSLog (@ "% @", dict );
NSLog (@ "% @", dict2 );
// The address of the returned value through the Input key
NSString * value = [dict objectForKey: @ "3"];
Value = dict [@ "3"];
// After Xcode 4.6
// If no corresponding key exists, nil is returned.
NSLog (@ "% @", value );
// Total number of return key-value pairs
NSUInteger count = [dict count];
NSLog (@ "% lu", count );
// Return all keys
NSArray * keys = [dict allKeys];
// Return all values
NSArray * values = [dict allValues];
// Traverse the dictionary
For (NSString * key in dict ){
// Each cycle key points to a key
// Uses the traversal key to indirectly traverse the value
NSLog (@ "% @", dict [key]);
}
NSMutableDictionary * mutableDict = [[NSMutableDictionary alloc] init];
// Reset the dictionary
[MutableDict setDictionary: @ {@ "1": @ "One", @ "2": @ "Two", @ "3": @ "Three"}];
// Add
[MutableDict setObject: @ "Four" forKey: @ "4"];
// Delete
// Delete a value using the key
[MutableDict removeObjectForKey: @ "3"];
// Delete multiple values using multiple keys
[MutableDict removeObjectsForKeys: @ [@ "1", @ "2", @ "3"];
// Delete all key-value pairs
[MutableDict removeAllObjects];
△Oc is a very beautiful language. Its names are basically a combination of words. You can learn about this method or the role of this variable through the name;