Reputation: 4313
How do I declare a dictionary using String as key, and containing Arrays as value in Swift?
This won't work:
var unloadedImagesRows:[String:[Int]()]! = [String:[Int]()]()
Upvotes: 0
Views: 67
Reputation: 4219
var unloadedImagesRows:[String: [Int]] = ["somekey": [1,2,3]]
or for an empty dictionary
var unloadedImagesRows:[String: [Int]] = [ : ]
Upvotes: 1
Reputation: 11682
This will work:
var unloadedImagesRows:[String:[Int]]! = [String:[Int]]()
Upvotes: 1
Reputation: 93161
You don't need to explicitly declare the type of the variable. Swift is often smart enough to infer the type from its value.
Try this:
var unloadedImagesRows = [String: [Int]]()
unloadedImagesRows["array1"] = [1,2,3,4]
unloadedImagesRows["array2"] = [5,6,7]
Upvotes: 2