NSDictionary的几种遍历方法

NSDictionary的几种遍历方法:

1、NSEnumerator 

NSEnumerator* keyEnum = [iDictionary keyEnumerator];
id key;
for(key = [keyEnum nextObject])
{
   //do something;
}

2、for key in ...

for (id key in iDictionary)
{
  //do something

}

3、NSDictionary allKeys

- (void)describeDictionary:(NSDictionary *dict)

{
 NSArray *keys;
 int i, count;
 id key, value;

 keys = [dict allKeys];
 count = [keys count];
 for (i = 0; i < count; i++)
  {
     key = [keys objectAtIndex: i];
     value = [dict objectForKey: key];
     NSLog (@"Key: %@ for value: %@", key, value);
  }
}

 

posted on 2015-08-19 16:43  隔热  阅读(3204)  评论(0编辑  收藏  举报