Learning to use the most appropriate class or object for the task at hand is fundamental to writing efficient code. This is especially true when dealing with collections.
Happily, thereâ€™s a document named Collections Programming Topics on Appleâ€™s Developer Library that explains in detail the differences between the available classes, as well as which situations suit each class. Itâ€™s a must read document for anyone looking to work with collections.
TLDR? Hereâ€™s a quick synopsis of the most common collection types:
- Arrays: Ordered list of values. Quick lookup by index, slow to lookup by value, slow to insert/delete.
- Dictionaries: Store key/value pairs. Quick lookups by key.
- Sets: Unordered list of values. Quick lookup by value, quick to insert/delete.
You must log in to post a comment.