Creating a dictionary

You can create a dictionary by assigning some initial values to it. Type the following into your playground and run it:

// Dictionaries
// Creating a dictionary
var contactList = ["Shah" : "+60123456789", "Akhil" : "+0223456789" ]

This creates a dictionary variable, contactList, with two key-value pairs inside it. Each key-value pair is a combination of a unique key and a value. You don't have to specify a type because Swift uses type inference to figure out the type based on the values you assigned. Note that the var keyword was used; this means you can change the contents of the dictionary after it has been created.

Now, let's see how to find out how many items there are in a dictionary.

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

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