# Associative arrays in Objective-C



## bauhsoj (Mar 22, 2005)

Does objective-c offer the ability to natively create associative arrays such as those in PHP, Perl, or JavaScript?


----------



## Viro (Mar 22, 2005)

Associative arrays are more commonly known as hash maps or hash tables. Here's the documentation for hash tables in Objective-C. http://developer.apple.com/document...ns.html#//apple_ref/doc/uid/20000055/BCIBDCCF


----------



## lurk (Mar 22, 2005)

You also might want to look at NSDictionary which is a bit closer to what you want in practice.


----------



## Viro (Mar 22, 2005)

That's cool. Didn't know about NSDictionary .


----------



## bauhsoj (Mar 22, 2005)

So which do you think would be best to start with for someone who programs primarily in PHP? NSDictionary or hash tables?

I am pretty new to objective-c and Cocoa, but I use associative arrays in almost every aspect of my code so I need to understand an equivalent structure in objective-c.


----------



## Viro (Mar 22, 2005)

Look at NSDictionary. The following page should get you started. http://developer.apple.com/document...ions/index.html#//apple_ref/doc/uid/10000034i


----------



## bauhsoj (Mar 22, 2005)

Viro said:
			
		

> Look at NSDictionary. The following page should get you started. http://developer.apple.com/document...ions/index.html#//apple_ref/doc/uid/10000034i



Thanks! 

Can Dictionaries be looped through using foreach to access both keys and values similar to the way it is done in PHP? I haven't found an example of that yet in the manual at the ADC.


----------

