-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Mastering Swift 5.3
By :

A collection groups multiple items into a single unit. Swift provides three native collection types. These collection types are arrays, dictionaries, and sets. Arrays store data in an ordered collection, dictionaries are unordered collections of key-value pairs, and sets are unordered collections of unique values. In an array, we access the data by the location or index within 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 a shortcoming, but actually helps eliminate common programming mistakes.
Let's start off...