1

In what situation does it make sense to use a dictionary versus a NSMutableArray?

Will
  • 11
  • 1
  • 1
    I'll just add that because you're comparing a "dictionary" to a "mutable array", you may want to read about the difference between mutable and immutable (or NSMutableArray vs. NSArray.) Dictionaries also come in mutable and immutable versions. – Marvo Apr 26 '11 at 01:23

2 Answers2

2

Those are 2 different types of containers. Array is a sequential data storage where you can retrieve elements by index. Dictionary is a hash where you retrieve elements by "names". Both have pros and cons (lookup speed, insertion time, enumeration, etc).

Please read on generic Array vs Hash.

Zepplock
  • 28,655
  • 4
  • 35
  • 50
0

Depends on your requirements.

If you need a collection of stuff, any order or even strictly ordered, and you need to iterate over the values, then perhaps an Array suffices.

If your data has a key and a unique key at that (serial number, login name, whatever) then a dictionary is going to give you quick access to the objects by key.

Marvo
  • 17,845
  • 8
  • 50
  • 74