10 Dictionaries

In the previous chapter, you became familiar with Swift’s Array type. The Array type is a useful collection when the order of the elements in the collection is important.

But order is not always important. Sometimes you simply want to hold on to a set of information in a container and then retrieve the information as needed. That is what dictionaries are for.

A Dictionary is a collection type that organizes its content by key-value pairs. The keys in a dictionary map onto values. A key is like the ticket you give to the attendant at a coat check. You hand your ticket over, and the attendant uses it to find your coat. Similarly, you give a key to an instance of the Dictionary type, and it returns to you the value ...

Get Swift Programming: The Big Nerd Ranch Guide 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.