Will
Will

Reputation: 11

Dictionary or Array

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

Upvotes: 1

Views: 904

Answers (2)

Marvo
Marvo

Reputation: 18143

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.

Upvotes: 0

Zepplock
Zepplock

Reputation: 29145

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.

Upvotes: 2

Related Questions