Iterating over a dictionary

You can use a for-in loop to iterate over every item in a dictionary. Type in and run the following code:

// Iterating over a dictionary
for (name, contactNumber) in contactList {
print("(name) : (contactNumber)")
}

This will print every item in the dictionary to the Debug area. Since dictionaries are unsorted, you may get the results in a different order when you run this code again.

This concludes the section on dictionaries. Let's look at the third collection type, sets. Sets are used to store an unordered list of values.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.126.199