A Dictionary is an unordered collection of mappings/associations from keys to values. It is very similar to a Set and has the same performance, but stores a key/value pair, and only the key has to be Hashable. It can be used for storing preferences, or when you have a group of named values where there are either too many or change too often to be hardcoded. Then, you can use the names as keys:


The full name is Dictionary<Key, Value>, but it is more commonly written as [Key: Value].

Dictionary ignores the order in which values are added or removed, and may change them arbitrarily, just like Set.

Working with Dictionaries

Now it's time to ...

Get Beginning Swift now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.