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);
  }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-09-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2021-05-19
  • 2021-09-16
  • 2022-12-23
相关资源
相似解决方案