NSDictionary
//官网原文:
TheNSDictionary
class declares the programmatic interface to objects that manage immutable associations of keys and values. Use this class or its subclassNSMutableDictionary
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 termdictionaryrefers 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 byisEqual:
). In general, a key can be any object (provided that it conforms to theNSCopying
protocol—see below), but note that when using key-value coding the key must be a string (seeKey-Value Coding Fundamentals). Neither a key nor a value can benil
; if you need to represent a null value in a dictionary, you should useNSNull
.
翻译:
使用NSDictionary用产生的对象是用来管理不变的键值对,使用它或者它的子类NSMutableDictionary可以很方便的使用key来查找到它所对应的value,使用NSDictionary 创建静态的(一经创建内容不可变)的字典, 而使用NSMutableDictionary创建动态的字典(内容可更改);
一个键值对在字典中被称为一个表项,每一个表项都有一个键和一个与该键对应的值,在字典中,所有的键都是唯一的,也就是说在一个字典中不存在两个相同的键,通常,一个键可以是任何OC中得对象,但是注意在使用key-value进行编码时,键必须是一个字符串,在字典中,键和值不能为nil,若需要将value置为nil,应写成NSNUll(mark:因为在对每个字典进行初始化时都是以nil作为结束);
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。