NSDictionary 常用方法

<1>创建方法

//实例化方法

- (id)initWithObjectsAndKeys:(id)firstObject, ...;

  - (id)initWithDictionary:(NSDictionary *)otherDictionary;

//类方法创建

  + (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;

  + (id)dictionaryWithDictionary:(NSDictionary *)dict;

  <2>获取键值对个数

  - (NSUInteger)count;

  <3>根据key 获取相应的值

  - (id)objectForKey:(id)aKey;

  <4>获取字典中所有的key

  - (NSArray *)allKeys;

  <5>获取值是anObject的所有的key

  - (NSArray *)allKeysForObject:(id)anObject;    

  <6>获取字典中所有的值

  - (NSArray *)allValues;

 

4 NSMutableDictionary

 

 

 

<1>增加

//增加整个字典

- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary;

//增加键值对

//key不存在表示增加 key存在表示修改key对应的值

  - (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey;

  <3>删除

//根据key删除键值对

  - (void)removeObjectForKey:(id)aKey;

//删除所有键值对

  - (void)removeAllObjects;

//根据数组中的内容删除相应的键值对

  - (void)removeObjectsForKeys:(NSArray *)keyArray;

  <4>修改

//修改整个字典

  - (void)setDictionary:(NSDictionary *)otherDictionary;

posted @ 2015-08-23 23:17  BN笨的很想飞  阅读(245)  评论(0编辑  收藏  举报