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

iOS 17 Programming for Beginners
By :

Let’s say you’re writing a Contacts app. You would need to store a list of names and their corresponding contact numbers. A dictionary would be perfect for this.
A dictionary stores key-value pairs in an unordered list. Here’s what it looks like:
Figure 5.3: Dictionary
All keys must be of the same type and must be unique. All values must be of the same type, but are not necessarily unique. Keys and values don’t have to be of the same type as each other. You use the key to get the corresponding value.
If you create a dictionary using the let
keyword, its contents can’t be changed after it has been created. If you want to change the contents after creation, use the var
keyword.
Let’s look at how to work with dictionaries. You’ll create a dictionary by assigning a value to it in the next section.
Imagine that you’re creating a Contacts app. For this app...