【发布时间】:2014-07-31 13:14:15
【问题描述】:
使用字典中的嵌套字符串数组(带有字符串索引),我正在尝试创建一个函数,该函数允许我在调用时循环遍历字典的每个索引并将其替换为空数组。但是,执行以下代码会返回以下错误
<swift-imported-modules>:1: missing submodule 'cocoa'<REPL>:16:29: error: could not find an overload for 'subscript' that accepts the supplied arguments category[index] = [] 我不知道为什么
如果我只打印index,我会得到预期的类别字符串,如果我手动将它们输入循环,它会起作用,这只发生在index 被替换时。展开也无济于事。
class myClass {
var category: Dictionary<String, Array<String>> = [
"cat1" : [],
"cat2" : [],
"cat3" : []
]
func eraseContent() {
for index in category {
category[index] = []
}
}
}
我也尝试查看参考指南,但没有找到 Swift 支持的 deleteAll 命令
【问题讨论】:
标签: arrays dictionary swift for-in-loop