From the course: Swift 5 Essential Training
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Swift dictionaries - Swift Tutorial
From the course: Swift 5 Essential Training
Swift dictionaries
- [Instructor] Like arrays, dictionaries are collection types, but instead of holding single values accessed by indexes, they hold key value pairs. Now in these key value pairs, all the keys need to be of the same type and all values need to be of the same type. Now, it's important to know that dictionary items are unordered, so their values are accessed by their associated keys not in sequence. Let's do the same thing we did with arrays and start off with a simple uninitialized dictionary. We're going to call this blacksmithShop and the syntax for a dictionary-type annotation is two brackets. The first type is going to be the type of key that we're going to store separated by a colon, a space, and the value type. So in plain English, we're saying here that blacksmithShop is going to be a dictionary of string keys and int values. To create or initialize an empty dictionary, we use the open and close brackets and a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Gathering inventory with collections24s
-
(Locked)
Swift arrays4m 27s
-
(Locked)
Core array methods6m 47s
-
(Locked)
Swift dictionaries5m 39s
-
Core dictionary methods7m 6s
-
(Locked)
Working with sets4m 12s
-
(Locked)
Core set methods3m 35s
-
(Locked)
Swift tuples5m 10s
-
Challenge: Merchant shop32s
-
(Locked)
Solution: Merchant shop5m 19s
-
(Locked)
-
-
-
-
-