Complete the code to create an empty dictionary named ages.
var ages: [String: Int] = [1]In Swift, an empty dictionary is created using [:]. This means no key-value pairs yet.
Complete the code to create a dictionary capitals with keys and values.
let capitals = [1]Swift dictionaries use square brackets with key-value pairs separated by colons.
Fix the error in accessing the value for key "apple" in the dictionary fruitColors.
let color = fruitColors[1]"apple"
In Swift, dictionary values are accessed using square brackets with the key inside.
Complete the code to create a dictionary scores with keys as player names and values as their scores.
var scores: [String: Int] = [1]Use square brackets with key-value pairs separated by colons to create a dictionary.
Complete the code to safely access the value for key "cat" in animalSounds and provide a default if missing.
let sound = animalSounds["cat"][1]"unknown"
Access dictionary value with square brackets, then use the nil-coalescing operator ?? to provide a default. Close the brackets properly.