Swift:设置嵌套字典的值?

时间:2014-09-03 22:14:11

标签: xcode swift xcode6

说我有这样的词典数组:

var dict = [
             [
        "subcategories": [
                            [ "name": "ATV", "type": "boolean", "value": "0"],
                            [ "name": "Bike Paths", "type": "boolean", "value": "0"]
                        ]
         ]
    ]

在游乐场,我可以像这样设置字典的值:

dict[0]["subcategories"]![1]["name"] = "abc"

但是在Xcode 5 Beta 5中,我得到了编译器错误(String, AnyObject) does not have a member name 'subscript'。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

听起来类型推断由于某种原因失败了 - 尝试明确声明类型:

var dict: Array<Dictionary<String, Array<Dictionary<String, String>>>> = [
    [
        "subcategories": [
            [ "name": "ATV", "type": "boolean", "value": "0"],
            [ "name": "Bike Paths", "type": "boolean", "value": "0"]
        ]
    ]
]