A collection groups multiple items into a single unit. Swift provides three native collection types. These collection types are arrays, sets, and dictionaries. Arrays store data in an ordered collection, sets are unordered collections of unique values, and dictionaries are unordered collections of key-value pairs. In an array, we access the data by the location or index in the array, whereas in a set we usually iterate through the collection, and dictionaries are accessed using a unique key.
The data stored in a Swift collection must be of the same type. This means, as an example, that we are unable to store a string value in an array of integers. Since Swift does not allow us to mismatch data types in a collection, we can be certain of the data type when we retrieve elements from a collection. This is another feature that, on the surface, might seem like...