[url]http://blog.objectgraph.com/index.php/2010/03/20/nsmutabledictionary-example-iphone-app-development-basics-in-objective-c/[/url]
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:@"John" forKey:@"Firstname"];
[dict setObject:@"Doe" forKey:@"Lastname"];
[dict setObject:@"info at objectgraph.com" forKey:@"Email"];
NSLog(@"%@", dict);
NSArray *keys = [dict allKeys];
// values in foreach loop
for (NSString *key in keys) {
NSLog(@"%@ is %@",key, [dict objectForKey:key]);
}
本文通过一个简单的Objective-C程序示例展示了如何使用NSMutableDictionary来设置键值对,并遍历字典中的所有条目。
528

被折叠的 条评论
为什么被折叠?



