HashTables在Cocoa [英] HashTables in Cocoa
问题描述
HashTables / HashMaps是存在的数据结构中最有用的(如果不是最常见的)数据结构之一。因此,在Cocoa开始学习编程时,我调查的第一件事是如何创建,填充和读取哈希表中的数据。
HashTables/HashMaps are one of the most (if not the most) useful of data-structures in existence. As such, one of the first things I investigated when starting to learn programming in Cocoa was how to create, populate, and read data from a hashtable.
令我惊讶的是:我一直在阅读的所有文档Cocoa / Objective-C编程似乎没有解释这一点。作为一个使用java.util的Java开发人员,就像它是一个身体的函数:我完全困惑于这。
To my surprise: all the documentation I've been reading on Cocoa/Objective-C programming doesn't seem to explain this much at all. As a Java developer that uses "java.util" as if it were a bodily function: I am utterly baffled by this.
所以,如果有人可以提供给我一个
So, if someone could provide me with a primer for creating, populating, and reading the contents of a hashtable: I would greatly appreciate it.
推荐答案
NSDictionary 和 NSMutableDictionary ?
这里有一个简单的例子:
And here's a simple example:
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:anObj forKey:@"foo"];
[dictionary objectForKey:@"foo"];
[dictionary removeObjectForKey:@"foo"];
[dictionary release];
这篇关于HashTables在Cocoa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!