Programming in Swift: Fundamentals

Oct 19 2021 Swift 5.5, iOS 15, Xcode 13

Part 4: More Collections

28. Creating & Populating 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: 27. Introduction Next episode: 29. Accessing & Working with 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.

You’re ready to learn about another extremely useful collection type in Swift: dictionaries.

var emptyDictionary: [String: Int] = [:]
var namesAndPets = ["Ron": "🐀 Rat"]
var namesAndPets = ["Ron": "🐀 Rat", "Rincewind": "🛄 Luggage", "Thor": "🔨 Hammer", "Goku": "☁️ Flying Nimbus"]
namesAndPets.updateValue("🐶 Mango", forKey: "Chris")
namesAndPets["Calvin"] = "🐯 Tiger"
namesAndPets.updateValue("Owl", forKey: "Ron")
namesAndPets["Ron"] = "🦉 Owl"