Programming in Swift: Fundamentals

Oct 19 2021 Swift 5.5, iOS 15, Xcode 13

Part 4: More Collections

29. Accessing & Working with Dictionaries

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions

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

Apple’s Swift Dictionary documentation: https://developer.apple.com/documentation/swift/dictionary

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 kodeco.com 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["Rincewind"]
namesAndPets["Captain Ahab"]
let captainAhabPet = namesAndPets["Captain Ahab"] ?? "No white whale for Captain Ahab"
namesAndPets.isEmpty
namesAndPets.count
namesAndPets.removeValue(forKey: "Goku")
namesAndPets["Hiccup"] = nil
print(namesAndPets)
for (character, pet) in namesAndPets {

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