用键和对象枚举NSDictionary,PHP样式

问题描述:

我知道您可以使用 NSEnumerator 枚举 NSMutableDictionary 的键或值。可以一起做吗?我正在寻找类似于PHP foreach 枚举器的东西,例如:

I know you can Enumerate the keys or values of NSMutableDictionary using NSEnumerator. Is it possible to do both together? I'm looking for something similar to the PHP foreach enumerator like:

foreach ($dictionary as $key => $value);


也许看看NSDictionary的方法:

Perhaps look into NSDictionary's method:

enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))

如果您不熟悉C / Objective-C中的块,那么这是一个很好的教程: http://thirdcog.eu/pwcblocks/

If you're not familiar with blocks in C/Objective-C, this is a good tutorial: http://thirdcog.eu/pwcblocks/