Dictionaries
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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.