November 2016
Intermediate to advanced
480 pages
14h 42m
English
Now that you have a mutable dictionary, how do you work with it? You will want to read from and modify the dictionary. Begin by using count to get some useful information about your dictionary.
Listing 10.2 Using count
import Cocoa
var movieRatings = ["Donnie Darko": 4, "Chungking Express": 5, "Dark City": 4]
print("I have rated \(movieRatings.count) movies.")
You should see in the console I have rated 3 movies.
Now let’s read a value from the movieRatings dictionary.
Listing 10.3 Reading a value from the dictionary
import Cocoa
var movieRatings = ["Donnie Darko": 4, "Chungking Express": 5, "Dark City": 4]
print("I have rated \(movieRatings.count) movies.")
let darkoRating = movieRatings["Donnie ...Read now
Unlock full access