Swift中的嵌套字典

Ben*_*bin 1 nsdictionary ios swift

这段代码有什么问题,我该如何解决这个问题呢?请解释一下你的答案,这样我就可以学习.我是Swift的新手,也是编程的新手.

var has: Dictionary<String, Dictionary<Dictionary, Int>> = [
    "Material" : [
        "Factory" : 0,
        "Raw" : 0,
        "Energy" : 0,
    ],
    "Workers" : [
        "Dev" : 0,
        "Builder" : 0,
        "Advertiser" : 0,
        "Consultant" : 0,
        "Engenier" : 0,
        "QA" : 0,
    ],
    "Assets" : [
        "Bonds" : 0,
    ],
    "Owe" : [
        "10%" = 0,
        "20%" = 0,
        "30%" = 0
    ],
    "Other" : [
        "Insurance" : 0
    ]
]
Run Code Online (Sandbox Code Playgroud)

Kir*_*ins 8

您已声明类型为Dictionary<String, Dictionary<Dictionary, Int>>,但文字实际上是Dictionary<String, Dictionary<String, Int>>.这也是非法语法:

"Owe" : [
    "10%" = 0,
    "20%" = 0,
    "30%" = 0
],
Run Code Online (Sandbox Code Playgroud)

应该:

"Owe" : [
    "10%" : 0,
    "20%" : 0,
    "30%" : 0
],
Run Code Online (Sandbox Code Playgroud)