Swift dictionary with array as value
ios, swift
Solution
Yes
let myDictionary: [String: [Int]] = ["Hello": [1, 2, 3], "World": [4, 5, 6]]
In fact, you don't even need the explicit type declaration if you assign an initial value in place. It can go as simple as:
let myDictionary = ["Hello": [1, 2, 3], "World": [4, 5, 6]]
To use the value:
println(myDictionary["Hello"][0]) // Print 1
println(myDictionary["World"][0]) // Print 4
Problem
How do you declare a dictionary that has an array as the value? Is this even possible?