Programming in Swift: Fundamentals

Oct 19 2021 Swift 5.5, iOS 15, Xcode 13

Part 4: More Collections

29. Accessing & Working with Dictionaries

Episode complete

Play next episode

Save for later
About this episode
See versions

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 28. Creating & Populating Dictionaries Next episode: 30. Challenge: Dictionaries

Apple’s Swift Dictionary documentation:

Update Notes: The student materials have been reviewed and are updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

Hey - welcome back! In the previous video, you learned about how to create dictionaries, how key-value storage works, and how to add and update elements in your dictionary. But there’s a whole lot more to dictionaries than just that!

namesAndPets["Captain Ahab"]
let captainAhabPet = namesAndPets["Captain Ahab"] ?? "No white whale for Captain Ahab"
namesAndPets.removeValue(forKey: "Goku")
namesAndPets["Hiccup"] = nil
for (character, pet) in namesAndPets {

for (character, pet) in namesAndPets {
  print("\(character) has a \(pet)")
for (name, _) in namesAndPets {
for pet in namesAndPets.keys {
for pet in namesAndPets.values {