//官网原文:
The NSDictionary
class declares the programmatic interface to objects that manage immutable associations of keys and values. Use this class or its subclass NSMutableDictionary
when you need a convenient and efficient way to retrieve data associated with an arbitrary key. NSDictionary
creates static dictionaries, andNSMutableDictionary
creates dynamic dictionaries. (For convenience, the term dictionary refers to any instance of one of these classes without specifying its exact class membership.)
A key-value pair within a dictionary is called an entry. Each entry consists of one object that represents the key and a second object that is that key’s value. Within a dictionary, the keys are unique. That is, no two keys in a single dictionary are equal (as determined by isEqual:
). In general, a key can be any object (provided that it conforms to the NSCopying
protocol—see below), but note that when using key-value coding the key must be a string (see Key-Value Coding Fundamentals). Neither a key nor a value can be nil
; if you need to represent a null value in a dictionary, you should use NSNull
.
翻译:
使用NSDictionary用产生的对象是用来管理不变的键值对,使用它或者它的子类NSMutableDictionary 可以很方便的使用key来查找到它所对应的value,使用NSDictionary 创建静态的(一经创建内容不可变)的字典, 而使用NSMutableDictionary创建动态的字典(内容可更改);
一个键值对在字典中被称为一个表项,每一个表项都有一个键和一个与该键对应的值,在字典中,所有的键都是唯一的,也就是说在一个字典中不存在两个相同的键,通常,一个键可以是任何OC中得对象,但是注意在使用key-value进行编码时,键必须是一个字符串,在字典中,键和值不能为nil,若需要将value置为nil,应写成NSNUll(mark:因为在对每个字典进行初始化时都是以nil作为结束);
转载于:https://blog.51cto.com/8947509/1556685