问题
In what situation does it make sense to use a dictionary versus a NSMutableArray?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/5784942/dictionary-or-array