您的位置:首页 > 其它

NSDictionary

2014-09-21 13:17 477 查看
//官网原文:The
NSDictionary
classdeclarestheprogrammaticinterfacetoobjectsthatmanageimmutableassociationsofkeysandvalues.Usethisclassoritssubclass
NSMutableDictionary
whenyouneedaconvenientandefficientwaytoretrievedataassociatedwithanarbitrarykey.
NSDictionary
createsstaticdictionaries,and
NSMutableDictionary
createsdynamicdictionaries.(Forconvenience,thetermdictionaryreferstoanyinstanceofoneoftheseclasseswithoutspecifyingitsexactclassmembership.)Akey-valuepairwithinadictionaryiscalledanentry.Eachentryconsistsofoneobjectthatrepresentsthekeyandasecondobjectthatisthatkey’svalue.Withinadictionary,thekeysareunique.Thatis,notwokeysinasingledictionaryareequal(asdeterminedby
isEqual:
).Ingeneral,akeycanbeanyobject(providedthatitconformstothe
NSCopying
protocol—seebelow),butnotethatwhenusingkey-valuecodingthekeymustbeastring(seeKey-ValueCodingFundamentals).Neitherakeynoravaluecanbe
nil
;ifyouneedtorepresentanullvalueinadictionary,youshoulduse
NSNull
.翻译:使用NSDictionary用产生的对象是用来管理不变的键值对,使用它或者它的子类NSMutableDictionary可以很方便的使用key来查找到它所对应的value,使用NSDictionary创建静态的(一经创建内容不可变)的字典,而使用NSMutableDictionary创建动态的字典(内容可更改);一个键值对在字典中被称为一个表项,每一个表项都有一个键和一个与该键对应的值,在字典中,所有的键都是唯一的,也就是说在一个字典中不存在两个相同的键,通常,一个键可以是任何OC中得对象,但是注意在使用key-value进行编码时,键必须是一个字符串,在字典中,键和值不能为nil,若需要将value置为nil,应写成NSNUll(mark:因为在对每个字典进行初始化时都是以nil作为结束);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息