Dictionary or Array
In what situation does it 开发者_运维技巧make sense to use a dictionary versus a NSMutableArray?
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.
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.
精彩评论