Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HashTables in 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.

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.

like image 736
Ryan Delucchi Avatar asked Jan 23 '09 20:01

Ryan Delucchi


1 Answers

NSDictionary and 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]; 
like image 63
Martin Gordon Avatar answered Sep 21 '22 20:09

Martin Gordon