I\'m practicing swift and I\'m trying to iterate over a Dictionary to print the key, but it gives me a
fatal error: Dictionary literal contains dupli
As others already said, you cannot create a dictionary where the same key does appear more then once.
That said I really like solution provided by luk2302
because if does offer a well structured approach.
Here I am just adding another solution.
Since the real information in your (wrong) dictionary is the value
(not the key) what's the meaning of using a Dictionary
?
You could simply use an array
let ages = [14, 15, 75, 43, 103, 87, 12]
ages.forEach { print($0) }