如何在NSMutableDictionary中使用NSEnumerator? [英] How to use NSEnumerator with NSMutableDictionary?

查看:145
本文介绍了如何在NSMutableDictionary中使用NSEnumerator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用NSEnumerator和NSMutableDictionary打印出所有键和值?

How do I use NSEnumerator with NSMutableDictionary, to print out all the keys and values?

谢谢!

推荐答案

除非你需要使用NSEnumerator,否则你可以使用快速枚举(更快)和简洁。

Unless you need to use NSEnumerator, you can use fast enumeration (which is faster) and concise.

for(NSString *aKey in myDictionary) {
    NSLog(@"%@", aKey);
    NSLog(@"%@", [[myDictionary valueForKey:aKey] string]); //made up method
}

此外,您可以使用具有快速枚举的枚举器:

Also you can use an Enumerator with fast enumeration:

NSEnumerator *enumerator = [myDictionary keyEnumerator];

for(NSString *aKey in enumerator) {
    NSLog(@"%@", aKey);
    NSLog(@"%@", [[myDictionary valueForKey:aKey] string]); //made up method
}

这对于执行反向枚举器等操作非常有用一个数组。

This is useful for things like doing the reverse enumerator in an array.

这篇关于如何在NSMutableDictionary中使用NSEnumerator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆